fix: complete goal resume and comment input follow-ups (#3361)
This commit is contained in:
committed by
GitHub
parent
f3f844463b
commit
7c9fdd1ee5
@@ -1,3 +1,5 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { Window } from 'happy-dom';
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import {
|
||||
@@ -80,6 +82,41 @@ describe('annotation overlay script', () => {
|
||||
expect(attachCall).toBeGreaterThan(imeGuard);
|
||||
});
|
||||
|
||||
test('preserves the overlay for composition Escape and cancels on ordinary Escape', async () => {
|
||||
const win = new Window({ url: 'http://annotation.test' });
|
||||
const run = new Function('window', 'document', 'requestAnimationFrame', `return ${script}`);
|
||||
try {
|
||||
const completion = run(win, win.document, (callback: FrameRequestCallback) => callback(0));
|
||||
const hostCount = win.document.body.children.length;
|
||||
expect(hostCount).toBeGreaterThan(0);
|
||||
for (const options of [{ isComposing: true }, { keyCode: 229 }]) {
|
||||
const event = new win.KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true, ...options });
|
||||
win.dispatchEvent(event);
|
||||
expect(event.defaultPrevented).toBe(false);
|
||||
expect(win.document.body.children.length).toBe(hostCount);
|
||||
}
|
||||
const escape = new win.KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true });
|
||||
win.dispatchEvent(escape);
|
||||
expect(escape.defaultPrevented).toBe(true);
|
||||
expect(await completion).toBeNull();
|
||||
expect(win.document.body.children.length).toBe(0);
|
||||
} finally {
|
||||
await win.happyDOM.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('guards app-side annotation Escape before cancelling the session', () => {
|
||||
const source = readFileSync(new URL('../../components/browser/BrowserPane.tsx', import.meta.url), 'utf8');
|
||||
const start = source.indexOf('const handler = (event: KeyboardEvent)');
|
||||
const end = source.indexOf("window.addEventListener('keydown', handler, true)", start);
|
||||
expect(start).toBeGreaterThan(-1);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
const handler = source.slice(start, end);
|
||||
const guard = handler.indexOf("if (isIMECompositionEvent(event) || event.key !== 'Escape') return;");
|
||||
expect(guard).toBeGreaterThan(-1);
|
||||
expect(handler.indexOf('cancelAnnotationSession(annotationHost)')).toBeGreaterThan(guard);
|
||||
});
|
||||
|
||||
test('escapes a label that would otherwise close the script', () => {
|
||||
const hostile = buildAnnotationOverlayScript(theme, {
|
||||
...labels,
|
||||
|
||||
@@ -535,6 +535,7 @@ export const buildAnnotationOverlayScript = (
|
||||
};
|
||||
|
||||
var onKeyDown = function (event) {
|
||||
if (event.isComposing || event.keyCode === 229) return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
Reference in New Issue
Block a user