Commit cde59e0a authored by csillag's avatar csillag

Simplify test cases

parent 2fbae287
...@@ -10,7 +10,6 @@ th.pluginInit() ...@@ -10,7 +10,6 @@ th.pluginInit()
describe 'Annotator.Plugin.TextHighlight', -> describe 'Annotator.Plugin.TextHighlight', ->
sandbox = null sandbox = null
jqElement = null
scrollTarget = null scrollTarget = null
createTestHighlight = -> createTestHighlight = ->
...@@ -29,15 +28,14 @@ describe 'Annotator.Plugin.TextHighlight', -> ...@@ -29,15 +28,14 @@ describe 'Annotator.Plugin.TextHighlight', ->
beforeEach -> beforeEach ->
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
sandbox.stub Annotator.TextHighlight, 'highlightRange', sandbox.stub Annotator.TextHighlight, 'highlightRange',
(normedRange, cssClass) -> "test highlight span" (normedRange, cssClass) ->
hl = document.createElement "hl"
hl.appendChild document.createTextNode "test highlight span"
hl
sandbox.stub Annotator.$.fn, "init", (selector, context) -> Annotator.$.fn.scrollintoview = sinon.spy (options) ->
jqElement = scrollTarget = this[0]
selector: selector options?.complete?()
data: sinon.spy()
scrollintoview: sinon.spy (options) ->
scrollTarget = this.selector
options?.complete?()
afterEach -> afterEach ->
sandbox.restore() sandbox.restore()
...@@ -50,22 +48,19 @@ describe 'Annotator.Plugin.TextHighlight', -> ...@@ -50,22 +48,19 @@ describe 'Annotator.Plugin.TextHighlight', ->
it 'stores the created highlight spans in _highlights', -> it 'stores the created highlight spans in _highlights', ->
hl = createTestHighlight() hl = createTestHighlight()
assert.equal hl._highlights, "test highlight span" assert.equal hl._highlights.textContent, "test highlight span"
it "wraps a jQuery element around the highlight span", ->
hl = createTestHighlight()
assert.equal jqElement.selector, "test highlight span"
it "assigns the annotation as data to the highlight span", -> it "assigns the annotation as data to the highlight span", ->
hl = createTestHighlight() hl = createTestHighlight()
assert.calledWith jqElement.data, "annotation", "test annotation" annotation = $(hl._highlights).data "annotation"
assert.equal annotation, "test annotation"
describe "scrollIntoView", -> describe "scrollIntoView", ->
it 'calls jQuery scrollintoview', -> it 'calls jQuery scrollintoview', ->
hl = createTestHighlight() hl = createTestHighlight()
hl.scrollIntoView() hl.scrollIntoView()
assert.called jqElement.scrollintoview assert.called Annotator.$.fn.scrollintoview
it 'scrolls to the created highlight span', -> it 'scrolls to the created highlight span', ->
hl = createTestHighlight() hl = createTestHighlight()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment