Commit 3646deda authored by Robert Knight's avatar Robert Knight

Add missing tests for `isSelectionBackwards`

parent 2f1fc9e0
import * as rangeUtil from '../range-util';
import { selectedRange } from '../range-util';
import { isSelectionBackwards, selectedRange } from '../range-util';
function createRange(node, start, end) {
const range = node.ownerDocument.createRange();
......@@ -210,6 +210,37 @@ describe('annotator/range-util', () => {
});
});
describe('isSelectionBackwards', () => {
let container;
beforeEach(() => {
container = document.createElement('div');
container.append('first', 'second');
document.body.append(container);
});
afterEach(() => {
container.remove();
});
[
{ nodeA: 0, offsetA: 5, nodeB: 0, offsetB: 2, backwards: true },
{ nodeA: 0, offsetA: 2, nodeB: 0, offsetB: 5, backwards: false },
{ nodeA: 1, offsetA: 0, nodeB: 0, offsetB: 0, backwards: true },
{ nodeA: 0, offsetA: 0, nodeB: 1, offsetB: 0, backwards: false },
].forEach(({ nodeA, offsetA, nodeB, offsetB, backwards }) => {
it('returns true if focus is before anchor', () => {
getSelection().setBaseAndExtent(
container.childNodes[nodeA],
offsetA,
container.childNodes[nodeB],
offsetB
);
assert.equal(isSelectionBackwards(getSelection()), backwards);
});
});
});
describe('itemsForRange', () => {
it('returns unique items for range', () => {
const range = document.createRange();
......
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