29 lines
1.4 KiB
JavaScript
29 lines
1.4 KiB
JavaScript
// The chat composer: IME confirmation never submits the draft, Shift+Enter
|
|
// inserts a newline, and ordinary Enter submits and clears.
|
|
const assert = require('node:assert/strict');
|
|
|
|
module.exports = async ({ page, go, shot }) => {
|
|
await go('/events');
|
|
const composer = page.getByRole('textbox', { name: 'Message Archie', exact: true });
|
|
await composer.waitFor();
|
|
await composer.fill('Composition in progress');
|
|
const sent = [];
|
|
await page.route('**/api/chat/stream', async route => {
|
|
sent.push(route.request().postDataJSON().text);
|
|
await route.fulfill({ contentType: 'text/event-stream', body: 'data: {"type":"done","text":"Test response"}\n\n' });
|
|
});
|
|
for (const event of [{ isComposing: true }, { keyCode: 229 }]) {
|
|
await composer.dispatchEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true, ...event });
|
|
assert.equal(await composer.inputValue(), 'Composition in progress', 'IME confirmation submitted the draft');
|
|
}
|
|
assert.equal(sent.length, 0);
|
|
await composer.press('Shift+Enter');
|
|
assert.ok((await composer.inputValue()).includes('\n'), 'Shift+Enter no longer inserts a newline');
|
|
await composer.fill('Ordinary Enter submits');
|
|
const request = page.waitForRequest('**/api/chat/stream');
|
|
await composer.press('Enter');
|
|
assert.equal((await request).postDataJSON().text, 'Ordinary Enter submits');
|
|
assert.equal(await composer.inputValue(), '');
|
|
await shot('chat-composition');
|
|
};
|