From b3f9be06398e8872cc64a966f99866b67e18c337 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 6 Jun 2015 23:15:32 -0400 Subject: Refactor and spec BlobView JS --- spec/javascripts/blob/blob_spec.js.coffee | 169 ++++++++++++++++++++++++++++++ spec/javascripts/fixtures/blob.html.haml | 9 ++ 2 files changed, 178 insertions(+) create mode 100644 spec/javascripts/blob/blob_spec.js.coffee create mode 100644 spec/javascripts/fixtures/blob.html.haml (limited to 'spec/javascripts') diff --git a/spec/javascripts/blob/blob_spec.js.coffee b/spec/javascripts/blob/blob_spec.js.coffee new file mode 100644 index 00000000000..a6f68a53f99 --- /dev/null +++ b/spec/javascripts/blob/blob_spec.js.coffee @@ -0,0 +1,169 @@ +#= require blob/blob + +describe 'BlobView', -> + fixture.preload('blob.html') + + clickLine = (number, eventData = {}) -> + if $.isEmptyObject(eventData) + $("#L#{number}").mousedown().click() + else + e = $.Event 'mousedown', eventData + $("#L#{number}").trigger(e).click() + + beforeEach -> + fixture.load('blob.html') + @class = new BlobView() + @spies = { + __setLocationHash__: spyOn(@class, '__setLocationHash__').and.callFake -> + } + + describe 'behavior', -> + it 'highlights one line given in the URL hash', -> + new BlobView('#L13') + expect($('#LC13')).toHaveClass('hll') + + it 'highlights a range of lines given in the URL hash', -> + new BlobView('#L5-25') + expect($('.hll').length).toBe(21) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..25] + + it 'scrolls to the first highlighted line on initial load', -> + spy = spyOn($, 'scrollTo') + new BlobView('#L5-25') + expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything()) + + it 'discards click events', -> + spy = spyOnEvent('a[data-line-number]', 'click') + clickLine(13) + expect(spy).toHaveBeenPrevented() + + it 'handles garbage input from the hash', -> + func = -> new BlobView('#tree-content-holder') + expect(func).not.toThrow() + + describe '#clickHandler', -> + it 'discards the mousedown event', -> + spy = spyOnEvent('a[data-line-number]', 'mousedown') + clickLine(13) + expect(spy).toHaveBeenPrevented() + + describe 'without shiftKey', -> + it 'highlights one line when clicked', -> + clickLine(13) + expect($('#LC13')).toHaveClass('hll') + + it 'unhighlights previously highlighted lines', -> + clickLine(13) + clickLine(20) + + expect($('#LC13')).not.toHaveClass('hll') + expect($('#LC20')).toHaveClass('hll') + + it 'sets the hash', -> + spy = spyOn(@class, 'setHash').and.callThrough() + clickLine(13) + expect(spy).toHaveBeenCalledWith(13) + + describe 'with shiftKey', -> + it 'sets the hash', -> + spy = spyOn(@class, 'setHash').and.callThrough() + clickLine(13) + clickLine(20, shiftKey: true) + expect(spy).toHaveBeenCalledWith(13) + expect(spy).toHaveBeenCalledWith(13, 20) + + describe 'without existing highlight', -> + it 'highlights the clicked line', -> + clickLine(13, shiftKey: true) + expect($('#LC13')).toHaveClass('hll') + expect($('.hll').length).toBe(1) + + it 'sets the hash', -> + spy = spyOn(@class, 'setHash') + clickLine(13, shiftKey: true) + expect(spy).toHaveBeenCalledWith(13) + + describe 'with existing single-line highlight', -> + it 'uses existing line as last line when target is lesser', -> + clickLine(20) + clickLine(15, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [15..20] + + it 'uses existing line as first line when target is greater', -> + clickLine(5) + clickLine(10, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + + describe 'with existing multi-line highlight', -> + beforeEach -> + clickLine(10, shiftKey: true) + clickLine(13, shiftKey: true) + + it 'uses target as first line when it is less than existing first line', -> + clickLine(5, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + + it 'uses target as last line when it is greater than existing first line', -> + clickLine(15, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [10..15] + + describe '#hashToRange', -> + beforeEach -> + @subject = @class.hashToRange + + it 'extracts a single line number from the hash', -> + expect(@subject('#L5')).toEqual([5, NaN]) + + it 'extracts a range of line numbers from the hash', -> + expect(@subject('#L5-15')).toEqual([5, 15]) + + it 'returns [NaN, NaN] when the hash is not a line number', -> + expect(@subject('#foo')).toEqual([NaN, NaN]) + + describe '#highlightLine', -> + beforeEach -> + @subject = @class.highlightLine + + it 'highlights the specified line', -> + @subject(13) + expect($('#LC13')).toHaveClass('hll') + + it 'accepts a String-based number', -> + @subject('13') + expect($('#LC13')).toHaveClass('hll') + + it 'returns undefined when given NaN', -> + expect(@subject(NaN)).toBe(undefined) + expect(@subject('foo')).toBe(undefined) + + describe '#highlightRange', -> + beforeEach -> + @subject = @class.highlightRange + + it 'returns undefined when first line is NaN', -> + expect(@subject([NaN, 15])).toBe(undefined) + expect(@subject(['foo', 15])).toBe(undefined) + + it 'returns undefined when given an invalid first line', -> + expect(@subject(['foo', 15])).toBe(undefined) + expect(@subject([NaN, NaN])).toBe(undefined) + expect(@subject('foo')).toBe(undefined) + + describe '#setHash', -> + beforeEach -> + @subject = @class.setHash + + it 'returns undefined when given an invalid first line', -> + expect(@subject('foo', 15)).toBe(undefined) + + it 'sets the location hash for a single line', -> + @subject(5) + expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5') + + it 'sets the location hash for a range', -> + @subject(5, 15) + expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5-15') diff --git a/spec/javascripts/fixtures/blob.html.haml b/spec/javascripts/fixtures/blob.html.haml new file mode 100644 index 00000000000..15ad1d8968f --- /dev/null +++ b/spec/javascripts/fixtures/blob.html.haml @@ -0,0 +1,9 @@ +#tree-content-holder + .file-content + .line-numbers + - 1.upto(25) do |i| + %a{href: "#L#{i}", id: "L#{i}", 'data-line-number' => i}= i + %pre.code.highlight + %code + - 1.upto(25) do |i| + %span.line{id: "LC#{i}"}= "Line #{i}" -- cgit v1.2.1 From 32366d18118281b32b5e770824d637a01d15093b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 15 Jun 2015 17:53:39 -0400 Subject: Rename BlobView to LineHighlighter --- spec/javascripts/blob/blob_spec.js.coffee | 169 --------------------- spec/javascripts/fixtures/blob.html.haml | 9 -- .../fixtures/line_highlighter.html.haml | 9 ++ spec/javascripts/line_highlighter_spec.js.coffee | 169 +++++++++++++++++++++ 4 files changed, 178 insertions(+), 178 deletions(-) delete mode 100644 spec/javascripts/blob/blob_spec.js.coffee delete mode 100644 spec/javascripts/fixtures/blob.html.haml create mode 100644 spec/javascripts/fixtures/line_highlighter.html.haml create mode 100644 spec/javascripts/line_highlighter_spec.js.coffee (limited to 'spec/javascripts') diff --git a/spec/javascripts/blob/blob_spec.js.coffee b/spec/javascripts/blob/blob_spec.js.coffee deleted file mode 100644 index a6f68a53f99..00000000000 --- a/spec/javascripts/blob/blob_spec.js.coffee +++ /dev/null @@ -1,169 +0,0 @@ -#= require blob/blob - -describe 'BlobView', -> - fixture.preload('blob.html') - - clickLine = (number, eventData = {}) -> - if $.isEmptyObject(eventData) - $("#L#{number}").mousedown().click() - else - e = $.Event 'mousedown', eventData - $("#L#{number}").trigger(e).click() - - beforeEach -> - fixture.load('blob.html') - @class = new BlobView() - @spies = { - __setLocationHash__: spyOn(@class, '__setLocationHash__').and.callFake -> - } - - describe 'behavior', -> - it 'highlights one line given in the URL hash', -> - new BlobView('#L13') - expect($('#LC13')).toHaveClass('hll') - - it 'highlights a range of lines given in the URL hash', -> - new BlobView('#L5-25') - expect($('.hll').length).toBe(21) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..25] - - it 'scrolls to the first highlighted line on initial load', -> - spy = spyOn($, 'scrollTo') - new BlobView('#L5-25') - expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything()) - - it 'discards click events', -> - spy = spyOnEvent('a[data-line-number]', 'click') - clickLine(13) - expect(spy).toHaveBeenPrevented() - - it 'handles garbage input from the hash', -> - func = -> new BlobView('#tree-content-holder') - expect(func).not.toThrow() - - describe '#clickHandler', -> - it 'discards the mousedown event', -> - spy = spyOnEvent('a[data-line-number]', 'mousedown') - clickLine(13) - expect(spy).toHaveBeenPrevented() - - describe 'without shiftKey', -> - it 'highlights one line when clicked', -> - clickLine(13) - expect($('#LC13')).toHaveClass('hll') - - it 'unhighlights previously highlighted lines', -> - clickLine(13) - clickLine(20) - - expect($('#LC13')).not.toHaveClass('hll') - expect($('#LC20')).toHaveClass('hll') - - it 'sets the hash', -> - spy = spyOn(@class, 'setHash').and.callThrough() - clickLine(13) - expect(spy).toHaveBeenCalledWith(13) - - describe 'with shiftKey', -> - it 'sets the hash', -> - spy = spyOn(@class, 'setHash').and.callThrough() - clickLine(13) - clickLine(20, shiftKey: true) - expect(spy).toHaveBeenCalledWith(13) - expect(spy).toHaveBeenCalledWith(13, 20) - - describe 'without existing highlight', -> - it 'highlights the clicked line', -> - clickLine(13, shiftKey: true) - expect($('#LC13')).toHaveClass('hll') - expect($('.hll').length).toBe(1) - - it 'sets the hash', -> - spy = spyOn(@class, 'setHash') - clickLine(13, shiftKey: true) - expect(spy).toHaveBeenCalledWith(13) - - describe 'with existing single-line highlight', -> - it 'uses existing line as last line when target is lesser', -> - clickLine(20) - clickLine(15, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [15..20] - - it 'uses existing line as first line when target is greater', -> - clickLine(5) - clickLine(10, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] - - describe 'with existing multi-line highlight', -> - beforeEach -> - clickLine(10, shiftKey: true) - clickLine(13, shiftKey: true) - - it 'uses target as first line when it is less than existing first line', -> - clickLine(5, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] - - it 'uses target as last line when it is greater than existing first line', -> - clickLine(15, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [10..15] - - describe '#hashToRange', -> - beforeEach -> - @subject = @class.hashToRange - - it 'extracts a single line number from the hash', -> - expect(@subject('#L5')).toEqual([5, NaN]) - - it 'extracts a range of line numbers from the hash', -> - expect(@subject('#L5-15')).toEqual([5, 15]) - - it 'returns [NaN, NaN] when the hash is not a line number', -> - expect(@subject('#foo')).toEqual([NaN, NaN]) - - describe '#highlightLine', -> - beforeEach -> - @subject = @class.highlightLine - - it 'highlights the specified line', -> - @subject(13) - expect($('#LC13')).toHaveClass('hll') - - it 'accepts a String-based number', -> - @subject('13') - expect($('#LC13')).toHaveClass('hll') - - it 'returns undefined when given NaN', -> - expect(@subject(NaN)).toBe(undefined) - expect(@subject('foo')).toBe(undefined) - - describe '#highlightRange', -> - beforeEach -> - @subject = @class.highlightRange - - it 'returns undefined when first line is NaN', -> - expect(@subject([NaN, 15])).toBe(undefined) - expect(@subject(['foo', 15])).toBe(undefined) - - it 'returns undefined when given an invalid first line', -> - expect(@subject(['foo', 15])).toBe(undefined) - expect(@subject([NaN, NaN])).toBe(undefined) - expect(@subject('foo')).toBe(undefined) - - describe '#setHash', -> - beforeEach -> - @subject = @class.setHash - - it 'returns undefined when given an invalid first line', -> - expect(@subject('foo', 15)).toBe(undefined) - - it 'sets the location hash for a single line', -> - @subject(5) - expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5') - - it 'sets the location hash for a range', -> - @subject(5, 15) - expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5-15') diff --git a/spec/javascripts/fixtures/blob.html.haml b/spec/javascripts/fixtures/blob.html.haml deleted file mode 100644 index 15ad1d8968f..00000000000 --- a/spec/javascripts/fixtures/blob.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -#tree-content-holder - .file-content - .line-numbers - - 1.upto(25) do |i| - %a{href: "#L#{i}", id: "L#{i}", 'data-line-number' => i}= i - %pre.code.highlight - %code - - 1.upto(25) do |i| - %span.line{id: "LC#{i}"}= "Line #{i}" diff --git a/spec/javascripts/fixtures/line_highlighter.html.haml b/spec/javascripts/fixtures/line_highlighter.html.haml new file mode 100644 index 00000000000..15ad1d8968f --- /dev/null +++ b/spec/javascripts/fixtures/line_highlighter.html.haml @@ -0,0 +1,9 @@ +#tree-content-holder + .file-content + .line-numbers + - 1.upto(25) do |i| + %a{href: "#L#{i}", id: "L#{i}", 'data-line-number' => i}= i + %pre.code.highlight + %code + - 1.upto(25) do |i| + %span.line{id: "LC#{i}"}= "Line #{i}" diff --git a/spec/javascripts/line_highlighter_spec.js.coffee b/spec/javascripts/line_highlighter_spec.js.coffee new file mode 100644 index 00000000000..d9a1ff2d5bb --- /dev/null +++ b/spec/javascripts/line_highlighter_spec.js.coffee @@ -0,0 +1,169 @@ +#= require line_highlighter + +describe 'LineHighlighter', -> + fixture.preload('line_highlighter.html') + + clickLine = (number, eventData = {}) -> + if $.isEmptyObject(eventData) + $("#L#{number}").mousedown().click() + else + e = $.Event 'mousedown', eventData + $("#L#{number}").trigger(e).click() + + beforeEach -> + fixture.load('line_highlighter.html') + @class = new LineHighlighter() + @spies = { + __setLocationHash__: spyOn(@class, '__setLocationHash__').and.callFake -> + } + + describe 'behavior', -> + it 'highlights one line given in the URL hash', -> + new LineHighlighter('#L13') + expect($('#LC13')).toHaveClass('hll') + + it 'highlights a range of lines given in the URL hash', -> + new LineHighlighter('#L5-25') + expect($('.hll').length).toBe(21) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..25] + + it 'scrolls to the first highlighted line on initial load', -> + spy = spyOn($, 'scrollTo') + new LineHighlighter('#L5-25') + expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything()) + + it 'discards click events', -> + spy = spyOnEvent('a[data-line-number]', 'click') + clickLine(13) + expect(spy).toHaveBeenPrevented() + + it 'handles garbage input from the hash', -> + func = -> new LineHighlighter('#tree-content-holder') + expect(func).not.toThrow() + + describe '#clickHandler', -> + it 'discards the mousedown event', -> + spy = spyOnEvent('a[data-line-number]', 'mousedown') + clickLine(13) + expect(spy).toHaveBeenPrevented() + + describe 'without shiftKey', -> + it 'highlights one line when clicked', -> + clickLine(13) + expect($('#LC13')).toHaveClass('hll') + + it 'unhighlights previously highlighted lines', -> + clickLine(13) + clickLine(20) + + expect($('#LC13')).not.toHaveClass('hll') + expect($('#LC20')).toHaveClass('hll') + + it 'sets the hash', -> + spy = spyOn(@class, 'setHash').and.callThrough() + clickLine(13) + expect(spy).toHaveBeenCalledWith(13) + + describe 'with shiftKey', -> + it 'sets the hash', -> + spy = spyOn(@class, 'setHash').and.callThrough() + clickLine(13) + clickLine(20, shiftKey: true) + expect(spy).toHaveBeenCalledWith(13) + expect(spy).toHaveBeenCalledWith(13, 20) + + describe 'without existing highlight', -> + it 'highlights the clicked line', -> + clickLine(13, shiftKey: true) + expect($('#LC13')).toHaveClass('hll') + expect($('.hll').length).toBe(1) + + it 'sets the hash', -> + spy = spyOn(@class, 'setHash') + clickLine(13, shiftKey: true) + expect(spy).toHaveBeenCalledWith(13) + + describe 'with existing single-line highlight', -> + it 'uses existing line as last line when target is lesser', -> + clickLine(20) + clickLine(15, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [15..20] + + it 'uses existing line as first line when target is greater', -> + clickLine(5) + clickLine(10, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + + describe 'with existing multi-line highlight', -> + beforeEach -> + clickLine(10, shiftKey: true) + clickLine(13, shiftKey: true) + + it 'uses target as first line when it is less than existing first line', -> + clickLine(5, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + + it 'uses target as last line when it is greater than existing first line', -> + clickLine(15, shiftKey: true) + expect($('.hll').length).toBe(6) + expect($("#LC#{line}")).toHaveClass('hll') for line in [10..15] + + describe '#hashToRange', -> + beforeEach -> + @subject = @class.hashToRange + + it 'extracts a single line number from the hash', -> + expect(@subject('#L5')).toEqual([5, NaN]) + + it 'extracts a range of line numbers from the hash', -> + expect(@subject('#L5-15')).toEqual([5, 15]) + + it 'returns [NaN, NaN] when the hash is not a line number', -> + expect(@subject('#foo')).toEqual([NaN, NaN]) + + describe '#highlightLine', -> + beforeEach -> + @subject = @class.highlightLine + + it 'highlights the specified line', -> + @subject(13) + expect($('#LC13')).toHaveClass('hll') + + it 'accepts a String-based number', -> + @subject('13') + expect($('#LC13')).toHaveClass('hll') + + it 'returns undefined when given NaN', -> + expect(@subject(NaN)).toBe(undefined) + expect(@subject('foo')).toBe(undefined) + + describe '#highlightRange', -> + beforeEach -> + @subject = @class.highlightRange + + it 'returns undefined when first line is NaN', -> + expect(@subject([NaN, 15])).toBe(undefined) + expect(@subject(['foo', 15])).toBe(undefined) + + it 'returns undefined when given an invalid first line', -> + expect(@subject(['foo', 15])).toBe(undefined) + expect(@subject([NaN, NaN])).toBe(undefined) + expect(@subject('foo')).toBe(undefined) + + describe '#setHash', -> + beforeEach -> + @subject = @class.setHash + + it 'returns undefined when given an invalid first line', -> + expect(@subject('foo', 15)).toBe(undefined) + + it 'sets the location hash for a single line', -> + @subject(5) + expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5') + + it 'sets the location hash for a range', -> + @subject(5, 15) + expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5-15') -- cgit v1.2.1 From e59aad6e83cbdafcaf100bb86f6fb925f2fb779e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 19 Jun 2015 02:01:53 -0400 Subject: Refactor LineHighlighter --- spec/javascripts/line_highlighter_spec.js.coffee | 63 +++++++++--------------- 1 file changed, 22 insertions(+), 41 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/line_highlighter_spec.js.coffee b/spec/javascripts/line_highlighter_spec.js.coffee index d9a1ff2d5bb..14fa487ff7f 100644 --- a/spec/javascripts/line_highlighter_spec.js.coffee +++ b/spec/javascripts/line_highlighter_spec.js.coffee @@ -13,6 +13,7 @@ describe 'LineHighlighter', -> beforeEach -> fixture.load('line_highlighter.html') @class = new LineHighlighter() + @css = @class.highlightClass @spies = { __setLocationHash__: spyOn(@class, '__setLocationHash__').and.callFake -> } @@ -20,12 +21,12 @@ describe 'LineHighlighter', -> describe 'behavior', -> it 'highlights one line given in the URL hash', -> new LineHighlighter('#L13') - expect($('#LC13')).toHaveClass('hll') + expect($('#LC13')).toHaveClass(@css) it 'highlights a range of lines given in the URL hash', -> new LineHighlighter('#L5-25') - expect($('.hll').length).toBe(21) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..25] + expect($(".#{@css}").length).toBe(21) + expect($("#LC#{line}")).toHaveClass(@css) for line in [5..25] it 'scrolls to the first highlighted line on initial load', -> spy = spyOn($, 'scrollTo') @@ -50,14 +51,14 @@ describe 'LineHighlighter', -> describe 'without shiftKey', -> it 'highlights one line when clicked', -> clickLine(13) - expect($('#LC13')).toHaveClass('hll') + expect($('#LC13')).toHaveClass(@css) it 'unhighlights previously highlighted lines', -> clickLine(13) clickLine(20) - expect($('#LC13')).not.toHaveClass('hll') - expect($('#LC20')).toHaveClass('hll') + expect($('#LC13')).not.toHaveClass(@css) + expect($('#LC20')).toHaveClass(@css) it 'sets the hash', -> spy = spyOn(@class, 'setHash').and.callThrough() @@ -75,8 +76,8 @@ describe 'LineHighlighter', -> describe 'without existing highlight', -> it 'highlights the clicked line', -> clickLine(13, shiftKey: true) - expect($('#LC13')).toHaveClass('hll') - expect($('.hll').length).toBe(1) + expect($('#LC13')).toHaveClass(@css) + expect($(".#{@css}").length).toBe(1) it 'sets the hash', -> spy = spyOn(@class, 'setHash') @@ -87,14 +88,14 @@ describe 'LineHighlighter', -> it 'uses existing line as last line when target is lesser', -> clickLine(20) clickLine(15, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [15..20] + expect($(".#{@css}").length).toBe(6) + expect($("#LC#{line}")).toHaveClass(@css) for line in [15..20] it 'uses existing line as first line when target is greater', -> clickLine(5) clickLine(10, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + expect($(".#{@css}").length).toBe(6) + expect($("#LC#{line}")).toHaveClass(@css) for line in [5..10] describe 'with existing multi-line highlight', -> beforeEach -> @@ -103,26 +104,26 @@ describe 'LineHighlighter', -> it 'uses target as first line when it is less than existing first line', -> clickLine(5, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [5..10] + expect($(".#{@css}").length).toBe(6) + expect($("#LC#{line}")).toHaveClass(@css) for line in [5..10] it 'uses target as last line when it is greater than existing first line', -> clickLine(15, shiftKey: true) - expect($('.hll').length).toBe(6) - expect($("#LC#{line}")).toHaveClass('hll') for line in [10..15] + expect($(".#{@css}").length).toBe(6) + expect($("#LC#{line}")).toHaveClass(@css) for line in [10..15] describe '#hashToRange', -> beforeEach -> @subject = @class.hashToRange it 'extracts a single line number from the hash', -> - expect(@subject('#L5')).toEqual([5, NaN]) + expect(@subject('#L5')).toEqual([5, null]) it 'extracts a range of line numbers from the hash', -> expect(@subject('#L5-15')).toEqual([5, 15]) - it 'returns [NaN, NaN] when the hash is not a line number', -> - expect(@subject('#foo')).toEqual([NaN, NaN]) + it 'returns [null, null] when the hash is not a line number', -> + expect(@subject('#foo')).toEqual([null, null]) describe '#highlightLine', -> beforeEach -> @@ -130,36 +131,16 @@ describe 'LineHighlighter', -> it 'highlights the specified line', -> @subject(13) - expect($('#LC13')).toHaveClass('hll') + expect($('#LC13')).toHaveClass(@css) it 'accepts a String-based number', -> @subject('13') - expect($('#LC13')).toHaveClass('hll') - - it 'returns undefined when given NaN', -> - expect(@subject(NaN)).toBe(undefined) - expect(@subject('foo')).toBe(undefined) - - describe '#highlightRange', -> - beforeEach -> - @subject = @class.highlightRange - - it 'returns undefined when first line is NaN', -> - expect(@subject([NaN, 15])).toBe(undefined) - expect(@subject(['foo', 15])).toBe(undefined) - - it 'returns undefined when given an invalid first line', -> - expect(@subject(['foo', 15])).toBe(undefined) - expect(@subject([NaN, NaN])).toBe(undefined) - expect(@subject('foo')).toBe(undefined) + expect($('#LC13')).toHaveClass(@css) describe '#setHash', -> beforeEach -> @subject = @class.setHash - it 'returns undefined when given an invalid first line', -> - expect(@subject('foo', 15)).toBe(undefined) - it 'sets the location hash for a single line', -> @subject(5) expect(@spies.__setLocationHash__).toHaveBeenCalledWith('#L5') -- cgit v1.2.1