test coverage for press and hold page up/down

This commit is contained in:
John McLear 2021-01-04 11:31:29 +00:00
parent 81e4c14fc0
commit ea010c92d5
2 changed files with 65 additions and 6 deletions

View file

@ -246,15 +246,28 @@ helper.pageUp = async (opts) => {
const caretNode = helper.padInner$.document.getSelection().anchorNode;
const event = new helper.padInner$.Event(helper.evtType);
event.which = 33;
if (opts) {
if (opts.shift) {
event.shiftKey = true;
}
}
helper.padInner$('#innerdocbody').trigger(event);
if (opts && opts.pressAndHold) {
let i = 0;
while (i < 100) {
// TODO: This triggers the same 100 times, not press and hold..
helper.padInner$('#innerdocbody').trigger(event);
i++;
}
await helper.waitForPromise(() => ((helper.padInner$.document.getSelection().anchorNode !== caretNode) && (i === 100)));
} else {
helper.padInner$('#innerdocbody').trigger(event);
// return as soon as the selection has changed
await helper.waitForPromise(() => helper.padInner$.document.getSelection().anchorNode !== caretNode);
}
// return as soon as the selection has changed
await helper.waitForPromise(() => helper.padInner$.document.getSelection().anchorNode !== caretNode);
};
/**
@ -266,15 +279,25 @@ helper.pageDown = async (opts) => {
const caretNode = helper.padInner$.document.getSelection().anchorNode;
const event = new helper.padInner$.Event(helper.evtType);
event.which = 34;
if (opts) {
if (opts.shift) {
event.shiftKey = true;
}
}
helper.padInner$('#innerdocbody').trigger(event);
// return as soon as the selection has changed
await helper.waitForPromise(() => helper.padInner$.document.getSelection().anchorNode !== caretNode);
if (opts && opts.pressAndHold) {
let i = 0;
while (i < 100) {
// TODO: This triggers the same 100 times, not press and hold..
helper.padInner$('#innerdocbody').trigger(event);
i++;
}
await helper.waitForPromise(() => ((helper.padInner$.document.getSelection().anchorNode !== caretNode) && (i === 100)));
} else {
helper.padInner$('#innerdocbody').trigger(event);
// return as soon as the selection has changed
await helper.waitForPromise(() => helper.padInner$.document.getSelection().anchorNode !== caretNode);
}
};
/**

View file

@ -432,3 +432,39 @@ describe('Shift Page Up/Down', function () {
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
});
describe('Press and Hold Page Up/Down', function () {
beforeEach(function (cb) {
helper.newPad({
cb: async () => {
await helper.clearPad();
// 200 lines
await helper.edit(
'\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' +
'\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' +
'\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' +
'\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' +
'\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
cb();
},
});
});
it('page up press and hold to top', async function () {
// by default page down when caret is at end of the document will leave it in the same place.
// viewport based pageup/down changes that
const initialLineNumber = helper.caretLineNumber();
helper.pageUp({
pressAndHold: true,
});
await helper.waitForPromise(() => helper.caretLineNumber() === 1);
});
it('page down press and hold to bottom', async function () {
// by default page down when caret is at end of the document will leave it in the same place.
// viewport based pageup/down changes that
const initialLineNumber = helper.caretLineNumber();
helper.pageDown({
pressAndHold: true,
});
await helper.waitForPromise(() => helper.caretLineNumber() === initialLineNumber);
});
});