Skip to content

Commit 3f45427

Browse files
committed
test(playwright): Add regression test for CJK IME input as first character
Signed-off-by: Jonas <jonas@freesources.org>
1 parent e9212e7 commit 3f45427

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

playwright/e2e/ime-input.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
// Ideas taken from https://github.com/microsoft/playwright/issues/5777 and https://github.com/slab/quill/commit/0ea789f95fc4956287b3995f9495aafa367d4190
7+
8+
import { type Locator, expect, mergeTests } from '@playwright/test'
9+
import { test as editorTest } from '../support/fixtures/editor'
10+
import { test as uploadFileTest } from '../support/fixtures/upload-file'
11+
12+
const test = mergeTests(editorTest, uploadFileTest)
13+
14+
test.beforeEach(async ({ open }) => {
15+
await open()
16+
})
17+
18+
let composingData = ''
19+
async function withKeyboardEvents(
20+
el: Locator,
21+
key: string,
22+
callback: () => Promise<void>,
23+
) {
24+
composingData += key
25+
await el.dispatchEvent('keydown', { key })
26+
await callback()
27+
await el.dispatchEvent('keyup', { key })
28+
}
29+
30+
test('Input Chinese character via IME at beginning of paragraph works', async ({
31+
browserName,
32+
editor,
33+
page,
34+
}) => {
35+
test.skip(
36+
browserName !== 'chromium',
37+
'IME testing is currently only implemented in Chromium API',
38+
)
39+
40+
// Get developer tools API
41+
const client = await page.context().newCDPSession(page)
42+
43+
await editor.content.focus()
44+
45+
await withKeyboardEvents(editor.content, 'w', async () => {
46+
client.send('Input.imeSetComposition', {
47+
selectionStart: composingData.length,
48+
selectionEnd: composingData.length,
49+
text: 'w',
50+
})
51+
})
52+
await withKeyboardEvents(editor.content, 'o', async () => {
53+
client.send('Input.imeSetComposition', {
54+
selectionStart: composingData.length,
55+
selectionEnd: composingData.length,
56+
text: 'o',
57+
})
58+
})
59+
await withKeyboardEvents(editor.content, 'Space', async () => {
60+
client.send('Input.insertText', {
61+
text: '我',
62+
})
63+
})
64+
65+
await expect(editor.content).toHaveText('我')
66+
})

0 commit comments

Comments
 (0)