Files
Jyotisha/frontend/tests/composer-ime-contract.test.ts
T
Jesse_Chen e8fa1ce4ea
Independent Staging Quality Gate / validate (push) Successful in 9m19s
Independent Staging Quality Gate / publish (push) Successful in 9m54s
fix(frontend): raise dark contrast, expand hit areas, and surface input limits
Dark muted surfaces missed WCAG AA; action and tertiary tokens plus a 32-pair contract close that. Hit targets, remaining-count, and Enter-to-send follow the interaction audit without changing visual sizes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 11:19:50 +08:00

45 lines
1.9 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const page = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8");
const rectification = readFileSync(
new URL("../src/components/rectification-agentic-chat.tsx", import.meta.url),
"utf8",
);
const guide = readFileSync(new URL("../src/components/birth-time-guide-turn.tsx", import.meta.url), "utf8");
function onKeyDownBlock(source: string, marker: string) {
const start = source.indexOf(marker);
assert.notEqual(start, -1, `missing onKeyDown near ${marker}`);
const slice = source.slice(start, start + 600);
const handler = slice.match(/onKeyDown=\{\(event\) => \{[\s\S]*?\n\s*\}\}/)
?? slice.match(/function handleComposerKeyDown[\s\S]*?\n \}/);
assert.ok(handler, `could not isolate onKeyDown from ${marker}`);
return handler[0];
}
test("all three composers ignore Enter while an IME is composing", () => {
const main = page.slice(
page.indexOf("function handleComposerKeyDown"),
page.indexOf("\n\n if (!hydrated"),
);
const rectificationHandler = onKeyDownBlock(rectification, "onKeyDown={(event) => {");
const guideHandler = onKeyDownBlock(guide, "onKeyDown={(event) => {");
for (const [name, handler] of [
["main composer", main],
["rectification composer", rectificationHandler],
["birth-time guide", guideHandler],
] as const) {
assert.match(handler, /event\.nativeEvent\.isComposing/, `${name} must ignore composing Enter`);
}
});
test("the guide turn sends with Enter and wraps with Shift+Enter, matching the other two", () => {
const handler = onKeyDownBlock(guide, "onKeyDown={(event) => {");
assert.match(handler, /event\.key === "Enter" && !event\.shiftKey/);
assert.doesNotMatch(handler, /metaKey \|\| event\.ctrlKey/);
assert.match(guide, /Enter 发送,Shift\+Enter 换行/);
});