mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
Ported enter ts.
This commit is contained in:
parent
4b40a794b1
commit
493005ce1c
2 changed files with 63 additions and 61 deletions
63
src/tests/frontend-new/specs/enter.spec.ts
Normal file
63
src/tests/frontend-new/specs/enter.spec.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
'use strict';
|
||||
import {expect, test} from "@playwright/test";
|
||||
import {getPadBody, goToNewPad, writeToPad} from "../helper/padHelper";
|
||||
|
||||
test.beforeEach(async ({ page })=>{
|
||||
await goToNewPad(page);
|
||||
})
|
||||
|
||||
test.describe('enter keystroke', function () {
|
||||
|
||||
test('creates a new line & puts cursor onto a new line', async function ({page}) {
|
||||
const padBody = await getPadBody(page);
|
||||
|
||||
// get the first text element out of the inner iframe
|
||||
const firstTextElement = padBody.locator('div').nth(0)
|
||||
|
||||
// get the original string value minus the last char
|
||||
const originalTextValue = await firstTextElement.textContent();
|
||||
|
||||
// simulate key presses to enter content
|
||||
await firstTextElement.click()
|
||||
await page.keyboard.press('Home');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
const updatedFirstElement = padBody.locator('div').nth(0)
|
||||
expect(await updatedFirstElement.textContent()).toBe('')
|
||||
|
||||
const newSecondLine = padBody.locator('div').nth(1);
|
||||
// expect the second line to be the same as the original first line.
|
||||
expect(await newSecondLine.textContent()).toBe(originalTextValue);
|
||||
});
|
||||
|
||||
test('enter is always visible after event', async function ({page}) {
|
||||
const padBody = await getPadBody(page);
|
||||
const originalLength = await padBody.locator('div').count();
|
||||
let lastLine = padBody.locator('div').last();
|
||||
|
||||
// simulate key presses to enter content
|
||||
let i = 0;
|
||||
const numberOfLines = 15;
|
||||
while (i < numberOfLines) {
|
||||
lastLine = padBody.locator('div').last();
|
||||
await lastLine.focus();
|
||||
await page.keyboard.press('End');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
// check we can see the caret..
|
||||
i++;
|
||||
}
|
||||
|
||||
expect(await padBody.locator('div').count()).toBe(numberOfLines + originalLength);
|
||||
|
||||
// is edited line fully visible?
|
||||
const lastDiv = padBody.locator('div').last()
|
||||
const lastDivOffset = await lastDiv.boundingBox();
|
||||
const bottomOfLastLine = lastDivOffset!.y + lastDivOffset!.height;
|
||||
const scrolledWindow = page.frames()[0];
|
||||
const windowOffset = await scrolledWindow.evaluate(() => window.pageYOffset);
|
||||
const windowHeight = await scrolledWindow.evaluate(() => window.innerHeight);
|
||||
|
||||
expect(windowOffset + windowHeight).toBeGreaterThan(bottomOfLastLine);
|
||||
});
|
||||
});
|
|
@ -1,61 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
describe('enter keystroke', function () {
|
||||
// create a new pad before each test run
|
||||
beforeEach(async function () {
|
||||
await helper.aNewPad();
|
||||
});
|
||||
|
||||
it('creates a new line & puts cursor onto a new line', async function () {
|
||||
this.timeout(2000);
|
||||
const inner$ = helper.padInner$;
|
||||
|
||||
// get the first text element out of the inner iframe
|
||||
const $firstTextElement = inner$('div').first();
|
||||
|
||||
// get the original string value minus the last char
|
||||
const originalTextValue = $firstTextElement.text();
|
||||
|
||||
// simulate key presses to enter content
|
||||
$firstTextElement.sendkeys('{enter}');
|
||||
|
||||
await helper.waitForPromise(() => inner$('div').first().text() === '');
|
||||
|
||||
const $newSecondLine = inner$('div').first().next();
|
||||
const newFirstTextElementValue = inner$('div').first().text();
|
||||
expect(newFirstTextElementValue).to.be(''); // expect the first line to be blank
|
||||
// expect the second line to be the same as the original first line.
|
||||
expect($newSecondLine.text()).to.be(originalTextValue);
|
||||
});
|
||||
|
||||
it('enter is always visible after event', async function () {
|
||||
const originalLength = helper.padInner$('div').length;
|
||||
let $lastLine = helper.padInner$('div').last();
|
||||
|
||||
// simulate key presses to enter content
|
||||
let i = 0;
|
||||
const numberOfLines = 15;
|
||||
let previousLineLength = originalLength;
|
||||
while (i < numberOfLines) {
|
||||
$lastLine = helper.padInner$('div').last();
|
||||
$lastLine.sendkeys('{enter}');
|
||||
await helper.waitForPromise(() => helper.padInner$('div').length > previousLineLength);
|
||||
previousLineLength = helper.padInner$('div').length;
|
||||
// check we can see the caret..
|
||||
|
||||
i++;
|
||||
}
|
||||
await helper.waitForPromise(
|
||||
() => helper.padInner$('div').length === numberOfLines + originalLength);
|
||||
|
||||
// is edited line fully visible?
|
||||
const lastLine = helper.padInner$('div').last();
|
||||
const bottomOfLastLine = lastLine.offset().top + lastLine.height();
|
||||
const scrolledWindow = helper.padChrome$('iframe')[0];
|
||||
await helper.waitForPromise(() => {
|
||||
const scrolledAmount =
|
||||
scrolledWindow.contentWindow.pageYOffset + scrolledWindow.contentWindow.innerHeight;
|
||||
return scrolledAmount >= bottomOfLastLine;
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue