etherpad-lite/tests/frontend/specs/pageupdown.js

258 lines
9.9 KiB
JavaScript
Raw Normal View History

2020-12-28 21:53:08 +01:00
'use strict';
2021-01-07 20:48:42 +00:00
describe('Page Up & Page Down', function () {
2020-12-28 21:53:08 +01:00
beforeEach(function (cb) {
helper.newPad({
cb: async () => {
await helper.clearPad();
// 200 lines
await helper.edit(
2020-12-29 23:44:43 +00:00
'\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' +
2020-12-28 21:53:08 +01:00
'\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' +
2021-01-03 11:51:35 +00:00
'\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\nhello');
2020-12-29 23:44:43 +00:00
cb();
},
2020-12-28 21:53:08 +01:00
});
});
2021-01-03 11:51:35 +00:00
// scrolls up 2 times
2020-12-29 23:44:43 +00:00
it('scrolls up on key stroke', async function () {
2021-01-03 11:51:35 +00:00
await helper.edit('Line 80', 80);
await helper.waitForPromise(() => 81 === helper.caretLineNumber());
// for some reason the page isn't inline with the edit
helper.padOuter$('#outerdocbody').parent().scrollTop(1000);
let intitialLineNumber = helper.caretLineNumber();
2020-12-28 21:53:08 +01:00
helper.pageUp();
2021-01-03 11:51:35 +00:00
await helper.waitForPromise(() => intitialLineNumber > helper.caretLineNumber());
intitialLineNumber = helper.caretLineNumber();
2020-12-28 21:53:08 +01:00
helper.pageUp();
2021-01-03 11:51:35 +00:00
await helper.waitForPromise(() => intitialLineNumber > helper.caretLineNumber());
2021-01-07 20:48:42 +00:00
await helper.waitForPromise(
() => helper.padOuter$('#outerdocbody').parent().scrollTop() < 1000
);
2020-12-29 23:44:43 +00:00
});
2020-12-28 21:53:08 +01:00
// scrolls down 3 times
2020-12-29 23:44:43 +00:00
it('scrolls down on key stroke', async function () {
2020-12-28 21:53:08 +01:00
// this places the caret in the first line
await helper.edit('Line 1', 1);
let currentLineNumber = helper.caretLineNumber();
helper.pageDown();
await helper.waitForPromise(() => currentLineNumber < helper.caretLineNumber());
currentLineNumber = helper.caretLineNumber();
helper.pageDown();
await helper.waitForPromise(() => currentLineNumber < helper.caretLineNumber());
currentLineNumber = helper.caretLineNumber();
helper.pageDown();
await helper.waitForPromise(() => currentLineNumber < helper.caretLineNumber());
2020-12-29 23:44:43 +00:00
});
});
describe('Viewport based Page Up/Down', function () {
2020-12-30 17:36:01 +00:00
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();
},
});
});
2021-01-03 12:15:34 +00:00
it('page up when top is at 100 and caret is at bottom', async function () {
2020-12-30 17:36:01 +00:00
// 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
2021-01-03 12:15:34 +00:00
const initialLineNumber = helper.caretLineNumber();
helper.pageDown();
2020-12-30 17:36:01 +00:00
helper.padOuter$('#outerdocbody').parent().scrollTop(100);
helper.pageUp();
2021-01-03 12:15:34 +00:00
await helper.waitForPromise(() => helper.caretLineNumber() < initialLineNumber);
});
it('page down when top is at 0 and caret is at 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.padOuter$('#outerdocbody').parent().scrollTop(0);
await helper.waitForPromise(() => helper.padOuter$('#outerdocbody').parent().scrollTop() === 0);
helper.pageUp(); // I think this might not be right..
helper.pageDown();
2021-01-07 20:48:42 +00:00
await helper.waitForPromise(() => (helper
.caretLineNumber() < initialLineNumber) && (helper.caretLineNumber() > 1));
2020-12-30 17:36:01 +00:00
});
});
describe('Shift Page Up/Down', function () {
beforeEach(function (cb) {
helper.newPad({
cb: async () => {
await helper.clearPad();
// 200 lines
2021-01-07 18:14:31 +00:00
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();
},
});
});
2021-01-07 20:09:54 +00:00
it('highlights lines on shift page down and releases them on page up', async function () {
await helper.edit('xxx', 1); // caret is offset 6
helper.pageUp();
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Caret');
});
2021-01-07 20:48:42 +00:00
it('highlights lines on shift pg down and maintains first selection on pg up', async function () {
await helper.edit('xxx', 1); // caret is offset 6
helper.pageUp();
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
2021-01-07 20:09:54 +00:00
2021-01-07 20:48:42 +00:00
it(`Highlights from end of document on pg up
then releases them on shift pg down`, async function () {
2021-01-07 20:09:54 +00:00
// TODO: JM NEEDS HELP: Why isn't this working? It works if you do the same in browser..
await helper.waitForPromise(() => helper.caretLineNumber() >= 201);
// make sure we're at bottom
helper.pageDown({
pressAndHold: true,
});
await helper.waitForPromise(() => helper.caretLineNumber() >= 201);
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Caret');
2021-01-07 20:48:42 +00:00
throw new Error('I NEED HELPZ PLZ');
});
2021-01-07 20:48:42 +00:00
it(`highlights from end of document on pg up twice
and retains on single pg down`, async function () {
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
2021-01-07 19:22:01 +00:00
2021-01-07 20:48:42 +00:00
it(`highlights from 3rd line on page up twice
should keep highlight`, async function () {
await helper.edit('xxx', 3); // caret is offset 6
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
2021-01-07 20:48:42 +00:00
xit(`highlights range forward then hit page up, selStart should be prior to initial
selStart and selEnd should be the original selStart`, async function () {
2021-01-07 19:22:01 +00:00
// TODO: JM Needs help, need a way to just select this line but it needs direction
// {select} wont cut the mustard
// selStartFocus is internal to rep
2021-01-07 18:14:31 +00:00
});
2021-01-07 20:48:42 +00:00
xit(`highlights (a few lines) range forwards then hit page down, selStart should be initial
selStart and selEnd further than original selEnd`, async function () {
throw new Error('JM TO DO');
2021-01-07 18:14:31 +00:00
});
2021-01-07 20:48:42 +00:00
xit(`highlights (a few lines) range backwards (rep.selFocusAtStart) then hit page up, selEnd
should be initial selStart,
selStart should be less than original selStart`, async function () {
throw new Error('JM TO DO');
2021-01-07 18:14:31 +00:00
});
2021-01-07 20:48:42 +00:00
xit(`highlights (a few lines) range backwards (rep.selFocusAtStart) then hit page down, selStart
should be initial selEnd and selEnd further than original selEnd`, async function () {
throw new Error('JM TO DO');
2021-01-07 18:14:31 +00:00
});
});
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
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);
});
});