Commit f0fd0897 authored by csillag's avatar csillag

Group and label single-phase tests

parent 06152dca
......@@ -28,9 +28,26 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
sandbox = null
pendingTest = null
watchForScroll = ->
new Promise (resolve, reject) ->
pendingTest = resolve: resolve
beforeEach ->
sandbox = sinon.sandbox.create()
sandbox.stub Annotator.TextHighlight, 'createFrom',
(segment, anchor, page) ->
segment: segment
anchor: anchor
page: page
removeFromDocument: sinon.spy()
scrollToView: sinon.spy -> pendingTest?.resolve()
afterEach ->
sandbox.restore()
pendingTest = null
describe "single-phase anchoring", ->
createTestAnnotation = (id, targets = 1) ->
id: "annotation " + id
target: (("target " + id + "-" + num) for num in [1 .. targets])
anchors: []
createAnchoringManager = ->
annotator =
......@@ -51,26 +68,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am
createTestAnnotation = (id, targets = 1) ->
id: "annotation " + id
target: (("target " + id + "-" + num) for num in [1 .. targets])
anchors: []
beforeEach ->
sandbox = sinon.sandbox.create()
sandbox.stub Annotator.TextHighlight, 'createFrom',
(segment, anchor, page) ->
segment: segment
anchor: anchor
page: page
removeFromDocument: sinon.spy()
scrollToView: sinon.spy -> pendingTest?.resolve()
afterEach ->
sandbox.restore()
pendingTest = null
describe "createAnchor", ->
describe "createAnchor() - single-phase", ->
it 'adds an anchor property to the annotations', ->
am = createAnchoringManager()
......@@ -88,6 +86,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am = createAnchoringManager()
ann = createTestAnnotation "a1"
anchor = am.createAnchor(ann, ann.target[0]).result
assert.equal anchor.annotation, ann
it 'adds a target property to the created anchors', ->
......@@ -101,12 +100,14 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am = createAnchoringManager()
ann = createTestAnnotation "a1"
anchor = am.createAnchor(ann, ann.target[0]).result
assert.equal anchor.id, "fake anchor for " + anchor.target.id
it 'adds the created anchors to the correct per-page array', ->
am = createAnchoringManager()
ann = createTestAnnotation "a1"
anchor = am.createAnchor(ann, ann.target[0]).result
assert.include am.anchors[anchor.startPage], anchor
it 'adds the created highlights to the anchors', ->
......@@ -115,8 +116,10 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
anchor = am.createAnchor(ann, ann.target[0]).result
assert.isObject anchor.highlight
page = anchor.startPage
hl = anchor.highlight[page]
assert.ok hl
assert.equal hl.page, page
......@@ -129,6 +132,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
anchor = am.createAnchor(ann, ann.target[0]).result
hl = anchor.highlight[anchor.startPage]
assert.calledWith am.annotator.publish, 'highlightsCreated', [hl]
it 'adds an anchor property to the created Highlights', ->
......@@ -138,9 +142,10 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
page = anchor.startPage
hl = anchor.highlight[page]
assert.equal hl.anchor, anchor
describe "getAnchors", ->
describe "getAnchors()", ->
it 'returns an empty array by default', ->
am = createAnchoringManager()
......@@ -185,10 +190,11 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
assert.include anchors, anchor2
assert.notInclude anchors, anchor3
describe 'getHighlights', ->
describe 'getHighlights()', ->
it 'returns an empty array by default', ->
am = createAnchoringManager()
hls = am.getHighlights()
assert.isArray hls
assert.equal hls.length, 0
......@@ -228,12 +234,13 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
assert.include hls, anchor2.highlight[anchor2.startPage]
assert.notInclude hls, anchor3.highlight[anchor3.startPage]
describe 'Anchor.scrollToView()', ->
describe 'Anchor.scrollToView() - single-phase', ->
it 'calls scrollIntoView() on the highlight', ->
am = createAnchoringManager()
ann = createTestAnnotation "a1"
anchor = am.createAnchor(ann, ann.target[0]).result
anchor.scrollToView()
assert.called anchor.highlight[anchor.startPage].scrollToView
describe 'two-phased anchoring', ->
......@@ -655,6 +662,10 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
describe 'when scrolling to a virtual anchor', ->
watchForScroll = ->
new Promise (resolve, reject) ->
pendingTest = resolve: resolve
it 'scrolls right next to the wanted page (to get it rendered)', ->
am = createAnchoringManagerAndLazyDocument()
ann = createTestAnnotationForPages "a1", [10]
......
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