测试文档只在需要的测试里安装。提示和圆点按项分开。清单「去做」走客户端跳转。输入框高亮在离开页面时清掉。六个没有入口的旧校正组件删掉。 Co-Authored-By: Grok (agent loop)
38 lines
1.9 KiB
TypeScript
38 lines
1.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import { rectificationChatSurface } from "./rectification-chat-surface.ts";
|
|
|
|
const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8");
|
|
// 原值: 读 rectification-agentic-chat.tsx 单文件。新值: rectificationChatSurface(容器 + 拆出的 hook / 参数函数 / 块,见 rectification-chat-surface.ts)。原因: TASK-rectification-code-split-20260926 只搬不改,整文件断言跟着代码走;切片断言另行改为调用函数。
|
|
const rectification = rectificationChatSurface;
|
|
|
|
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("the live composers ignore Enter while an IME is composing", () => {
|
|
// 原值: 首页、校正对话、旧引导轮三处都要忽略组字中的 Enter。
|
|
// 新值: 首页和校正对话两处。两处仍是 Enter 发送、Shift+Enter 换行。
|
|
// 原因: 旧引导轮组件没有入口,已删除。
|
|
const main = page.slice(
|
|
page.indexOf("function handleComposerKeyDown"),
|
|
page.indexOf("\n\n if (!hydrated"),
|
|
);
|
|
const rectificationHandler = onKeyDownBlock(rectification, "onKeyDown={(event) => {");
|
|
|
|
for (const [name, handler] of [
|
|
["main composer", main],
|
|
["rectification composer", rectificationHandler],
|
|
] as const) {
|
|
assert.match(handler, /event\.nativeEvent\.isComposing/, `${name} must ignore composing Enter`);
|
|
assert.match(handler, /event\.key === "Enter" && !event\.shiftKey/, `${name} must send on Enter`);
|
|
}
|
|
});
|