Commit f0fd0897 authored by csillag's avatar csillag

Group and label single-phase tests

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