mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(ci): today's changes pass the release gates
- iOS: the navigation proxy reports an error page through a callback the controller sets; it called the controller's method on itself and did not build. - keyboard: the done key reads the field's text in the capture phase, before the field's own handler, so a list that adds an item on Enter and clears itself keeps the keyboard; the tests wire it as the app does. - Ireland migration: the queued writes use addSql instead of awaiting inside loops; only table constants and integer ids reach the SQL. - tests: the Dawarich GL test types its two layer specs once (strict baseline lowered), the collab test reads the id off the listed message, the reasoning test runs its four servers in parallel, and a wasm copy covers the precompressed branch without a charset. - en wording: the deviations agreement no longer calls TREK self-hosted.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { closeOnDone, prepareField, prepareKeyboardFields } from './keyboardFields';
|
||||
import { prepareField, prepareKeyboardFields } from './keyboardFields';
|
||||
|
||||
function field(html: string): HTMLInputElement {
|
||||
document.body.innerHTML = html;
|
||||
@@ -91,40 +91,46 @@ describe('prepareKeyboardFields', () => {
|
||||
});
|
||||
|
||||
describe('closeOnDone', () => {
|
||||
const enter = (el: HTMLElement) => el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
||||
// Wired the way the app wires it: on the document, in the capture phase,
|
||||
// ahead of every handler the field has of its own.
|
||||
const enter = (el: HTMLElement) =>
|
||||
el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }));
|
||||
let stop: () => void = () => {};
|
||||
afterEach(() => {
|
||||
stop();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('closes the keyboard when nothing took the Enter of a "done" field', () => {
|
||||
vi.useFakeTimers();
|
||||
stop = prepareKeyboardFields(document);
|
||||
const el = field('<input name="title" enterkeyhint="done">');
|
||||
el.focus();
|
||||
el.addEventListener('keydown', closeOnDone);
|
||||
enter(el);
|
||||
vi.runAllTimers();
|
||||
expect(document.activeElement).not.toBe(el);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('keeps the keyboard for a field that acted on the Enter and cleared itself', () => {
|
||||
vi.useFakeTimers();
|
||||
stop = prepareKeyboardFields(document);
|
||||
const el = field('<input name="item" enterkeyhint="done">');
|
||||
el.value = 'Socks';
|
||||
el.focus();
|
||||
el.addEventListener('keydown', () => {
|
||||
el.value = '';
|
||||
});
|
||||
el.addEventListener('keydown', closeOnDone);
|
||||
enter(el);
|
||||
vi.runAllTimers();
|
||||
expect(document.activeElement).toBe(el);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('leaves "go" and "search" fields and handled Enters alone', () => {
|
||||
vi.useFakeTimers();
|
||||
stop = prepareKeyboardFields(document);
|
||||
for (const hint of ['go', 'search']) {
|
||||
const el = field(`<input enterkeyhint="${hint}">`);
|
||||
el.focus();
|
||||
el.addEventListener('keydown', closeOnDone);
|
||||
enter(el);
|
||||
vi.runAllTimers();
|
||||
expect(document.activeElement).toBe(el);
|
||||
@@ -132,10 +138,8 @@ describe('closeOnDone', () => {
|
||||
const handled = field('<input enterkeyhint="done">');
|
||||
handled.focus();
|
||||
handled.addEventListener('keydown', (e) => e.preventDefault());
|
||||
handled.addEventListener('keydown', closeOnDone);
|
||||
handled.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }));
|
||||
enter(handled);
|
||||
vi.runAllTimers();
|
||||
expect(document.activeElement).toBe(handled);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,14 +110,19 @@ export function prepareField(target: EventTarget | null): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** Enter on a "done" field that nothing acted on closes the keyboard. */
|
||||
/**
|
||||
* Enter on a "done" field that nothing acted on closes the keyboard. Listens in
|
||||
* the capture phase, so the field's text is read before any handler of the field
|
||||
* runs; whether one took the Enter is read off the event once it has gone round.
|
||||
*/
|
||||
export function closeOnDone(e: KeyboardEvent): void {
|
||||
const el = e.target;
|
||||
if (e.key !== 'Enter' || e.isComposing || e.defaultPrevented) return;
|
||||
if (e.key !== 'Enter' || e.isComposing) return;
|
||||
if (!(el instanceof HTMLInputElement) || el.getAttribute('enterkeyhint') !== 'done') return;
|
||||
const before = el.value;
|
||||
// After every handler of this Enter, including ones React schedules.
|
||||
setTimeout(() => {
|
||||
if (e.defaultPrevented) return;
|
||||
if (el.ownerDocument.activeElement === el && el.value === before) el.blur();
|
||||
}, 0);
|
||||
}
|
||||
@@ -128,11 +133,11 @@ export function prepareKeyboardFields(doc: Document = document): () => void {
|
||||
const onFocus = (e: FocusEvent) => prepareField(e.target);
|
||||
doc.addEventListener('touchstart', onTouch, { capture: true, passive: true });
|
||||
doc.addEventListener('focusin', onFocus, true);
|
||||
// Bubbling, so a field's own handler runs first and can take the Enter.
|
||||
doc.addEventListener('keydown', closeOnDone);
|
||||
// Capturing, so the text is read before the field's own handler can change it.
|
||||
doc.addEventListener('keydown', closeOnDone, true);
|
||||
return () => {
|
||||
doc.removeEventListener('touchstart', onTouch, { capture: true });
|
||||
doc.removeEventListener('focusin', onFocus, true);
|
||||
doc.removeEventListener('keydown', closeOnDone);
|
||||
doc.removeEventListener('keydown', closeOnDone, true);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user