From cc9b258c8d6e2ac5ec0664c90ed203cbf753eef7 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 19 Sep 2026 01:18:32 -0700 Subject: [PATCH] test(editor): select rich copy ranges through Playwright --- tests/e2e/markdown-copy-formatting.spec.ts | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/tests/e2e/markdown-copy-formatting.spec.ts b/tests/e2e/markdown-copy-formatting.spec.ts index 8ea3a3e638e..57caacde2c5 100644 --- a/tests/e2e/markdown-copy-formatting.spec.ts +++ b/tests/e2e/markdown-copy-formatting.spec.ts @@ -23,15 +23,7 @@ test('copying a rich selection preserves Markdown formatting', async ({ orcaPage await openMarkdownFixture(orcaPage, context, filePath) const editor = await waitForRichMarkdownEditor(orcaPage) await expect(editor.locator('strong')).toHaveText('bold') - await editor.locator('p').evaluate((paragraph) => { - const range = document.createRange() - range.selectNodeContents(paragraph) - const selection = window.getSelection() - selection?.removeAllRanges() - selection?.addRange(range) - paragraph.closest('[contenteditable]')?.focus() - document.dispatchEvent(new Event('selectionchange')) - }) + await editor.locator('p').selectText() await expect .poll(() => orcaPage.evaluate(() => window.getSelection()?.toString())) .toBe('A bold paragraph with a link.') @@ -54,15 +46,7 @@ test('copying a rich selection preserves Markdown formatting', async ({ orcaPage await expect(editor.locator('p')).toHaveText('A bold paragraph with a link.') await testInfo.attach('copied-markdown', { body: copied.text, contentType: 'text/markdown' }) - await editor.evaluate((element) => { - const range = document.createRange() - range.selectNodeContents(element) - const selection = window.getSelection() - selection?.removeAllRanges() - selection?.addRange(range) - element.focus() - document.dispatchEvent(new Event('selectionchange')) - }) + await editor.selectText() await expect .poll(() => orcaPage.evaluate(() => window.getSelection()?.toString())) .toContain('Copy formatting')