From 8e6639b770398ebb606eef97d48040dd633862b1 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Mon, 5 Apr 2021 15:06:41 -0700 Subject: [PATCH] test(keyboard): add test with contenteditable and selection (#5938) --- tests/page-keyboard.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/page-keyboard.spec.ts b/tests/page-keyboard.spec.ts index 670eee498f..612e314340 100644 --- a/tests/page-keyboard.spec.ts +++ b/tests/page-keyboard.spec.ts @@ -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(`
`); + 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(`
`); + 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 = {