test(keyboard): add test with contenteditable and selection (#5938)

This commit is contained in:
Joel Einbinder 2021-04-05 15:06:41 -07:00 committed by GitHub
parent e3cf675624
commit 8e6639b770
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -420,6 +420,28 @@ it('should scroll with PageDown', async ({page, server}) => {
await page.waitForFunction(() => scrollY > 0);
});
it('should move around the selection in a contenteditable', async ({page, isMac}) => {
await page.setContent(`<div contenteditable></div>`);
await page.focus('div');
const modifier = isMac ? 'Alt' : 'Control';
await page.keyboard.type('Hello World');
await page.keyboard.down(modifier);
await page.keyboard.down('Shift');
await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');
await page.keyboard.up(modifier);
expect(await page.evaluate(() => window.getSelection().toString())).toBe('World');
});
it('should move to the start of the document', async ({page, isMac}) => {
it.skip(!isMac);
await page.setContent(`<div contenteditable></div>`);
await page.focus('div');
await page.keyboard.type('1\n2\n3\n');
await page.keyboard.press('Shift+Meta+ArrowUp');
expect(await page.evaluate(() => window.getSelection().toString())).toBe('1\n2\n3\n');
});
async function captureLastKeydown(page) {
const lastEvent = await page.evaluateHandle(() => {
const lastEvent = {