Commit bd223ffc authored by Robert Knight's avatar Robert Knight

Improve tests for invalid position selectors

Add tests to cover the cases where the position is on a page before the
quote and where the position is negative.
parent d061e027
...@@ -310,34 +310,42 @@ describe('annotator/anchoring/pdf', () => { ...@@ -310,34 +310,42 @@ describe('annotator/anchoring/pdf', () => {
[ [
{ {
// Position on same page as quote but different text. // Position on page before quote.
offset: 5, offset: 5,
}, },
{ {
// Position on a different page to the quote. // Position same page as quote, but different location.
offset: fixtures.pdfPages[0].length + 10, offset: fixtures.pdfPages[0].length + 1,
}, },
{ {
// Position invalid for document. // Position on a page after the quote.
offset: fixtures.pdfPages[0].length + fixtures.pdfPages[1].length + 5,
},
{
// Position before beginning of document.
offset: -500,
},
{
// Position beyond end of document.
offset: 100000, offset: 100000,
}, },
].forEach(({ offset }) => { ].forEach(({ offset }) => {
it('anchors using a quote if the position selector fails', () => { it('anchors using a quote if the position selector fails', () => {
viewer.pdfViewer.setCurrentPage(0); viewer.pdfViewer.setCurrentPage(1);
const range = findText(container, 'Pride And Prejudice'); const selection = 'zombie in possession';
const range = findText(container, selection);
return pdfAnchoring return pdfAnchoring
.describe(container, range) .describe(container, range)
.then(selectors => { .then(([, quote]) => {
const position = selectors[0]; const position = {
const quote = selectors[1]; type: 'TextPositionSelector',
start: offset,
position.start += offset; end: offset + selection.length,
position.end += offset; };
return pdfAnchoring.anchor(container, [position, quote]); return pdfAnchoring.anchor(container, [position, quote]);
}) })
.then(range => { .then(range => {
assert.equal(range.toString(), 'Pride And Prejudice'); assert.equal(range.toString(), selection);
}); });
}); });
}); });
......
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