Commit f208cf46 authored by Robert Knight's avatar Robert Knight

Add test to check handling of null selection

There is a difference between an empty selection and no selection at
all. In the latter case APIs such as `selection.getRangeAt(0)` will
throw an error.
parent bb1dc45e
......@@ -85,6 +85,8 @@ describe('annotator/plugin/pdf', () => {
it('hides annotation layers when there is a text selection', async () => {
// This tests checks for a CSS class on the root PDF viewer element.
// The annotation layers are hidden by a CSS rule that uses this class.
// Start with an empty selection.
const selection = window.getSelection();
if (!selection.isCollapsed) {
selection.collapseToStart();
......@@ -92,13 +94,20 @@ describe('annotator/plugin/pdf', () => {
pdfPlugin = createPDFPlugin();
assert.isFalse(pdfViewerHasClass('is-selecting'));
// Make the selection non-empty.
selection.selectAllChildren(document.body);
await awaitEvent(document, 'selectionchange');
assert.isTrue(pdfViewerHasClass('is-selecting'));
// Then make the selection empty again.
selection.collapseToStart();
await awaitEvent(document, 'selectionchange');
assert.isFalse(pdfViewerHasClass('is-selecting'));
// Finally, remove the selection entirely.
selection.removeAllRanges();
await awaitEvent(document, 'selectionchange');
assert.isFalse(pdfViewerHasClass('is-selecting'));
});
describe('#destroy', () => {
......
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