muse-agent-example/web/tests/交互/动态字段与结构过期.test.tsx
zizi ae02fd1732 前端:工作台页面、事件标签与旅程用例
- 上下文清单、任务列表与详情、恢复控制、运行观察、创作对话与消息流、正式变更决策面板、正文写作与候选审阅、资料研究等页面同步本轮后端能力。
- 事件标签表补齐后端事件类型;查询键与生成客户端随 HTTP 契约重新生成。
- 依赖调整后 lockfile 同步;交互用例与浏览器旅程 spec 一并更新。
- 证据:make 前端检查(lint + typecheck + Pi 工具桥 tsc)exit 0;make 前端测试 37 文件 / 120 用例通过。
2026-09-18 01:15:07 +08:00

96 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { afterEach, expect, it } from "vitest";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { Ui结构表单 } from "../../src/界面/结构表单/结构表单";
import { 生成字段修改, 投影表单值 } from "../../src/界面/结构表单/投影会话";
afterEach(cleanup);
// @muse-case {"case_id":"NC-form-rebase-intent","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"本地只改名称,服务器另改摘要","when":"冲突后刷新并保存","then":["只提交作者改动,服务器新摘要保留"],"contract":"docs/系统架构/新版设计/接口契约/元数据投影与版本.md"}
it("NC-form-rebase-intent:冲突刷新只保留作者真正改动的字段", async () => {
const schema = {
type: "object",
properties: { 名称: { type: "string" }, 摘要: { type: "string" } },
};
let output: unknown;
const submit = async (changes: unknown) => {
output = changes;
};
const view = render(
<Ui结构表单
visible={schema}
editable={schema}
initial={{ 名称: "旧名", 摘要: "旧摘要" }}
onSubmit={submit}
/>,
);
fireEvent.change(screen.getByLabelText("名称"), {
target: { value: "我改的名字" },
});
view.rerender(
<Ui结构表单
visible={schema}
editable={schema}
initial={{ 名称: "旧名", 摘要: "服务器新摘要" }}
onSubmit={submit}
/>,
);
expect((screen.getByLabelText("摘要") as HTMLInputElement).value).toBe(
"服务器新摘要",
);
fireEvent.click(screen.getByRole("button", { name: "保存档案" }));
expect(output).toEqual([{ 路径: ["名称"], 动作: "set", 值: "我改的名字" }]);
});
// @muse-case {"case_id":"NC-form-editable-projection","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"嵌套字段可见与可编辑集合不同","when":"修改一个叶子并保存","then":["隐藏值不显示,只读值不可改,提交叶子修改而非浅替换"],"contract":"docs/系统架构/新版设计/接口契约/元数据投影与版本.md"}
it("NC-form-editable-projection:嵌套字段只提交可编辑叶子并隐藏受限值", async () => {
const visible = {
type: "object",
properties: {
人物: {
type: "object",
properties: {
姓名: { type: "string", title: "姓名" },
编号: { type: "string", title: "编号" },
},
},
},
};
const editable = {
type: "object",
properties: {
人物: { type: "object", properties: { 姓名: { type: "string" } } },
},
};
const base = { 人物: { 姓名: "旧名", 编号: "只读身份", 秘密: "不可显示" } };
let output: unknown;
render(
<Ui结构表单
visible={visible}
editable={editable}
initial={base}
onSubmit={async (changes) => {
output = changes;
}}
/>,
);
expect(screen.queryByText("不可显示")).toBeNull();
expect((screen.getByLabelText("编号") as HTMLInputElement).readOnly).toBe(
true,
);
fireEvent.change(screen.getByLabelText("姓名"), {
target: { value: "新名" },
});
fireEvent.click(screen.getByRole("button", { name: "保存档案" }));
expect(output).toEqual([{ 路径: ["人物", "姓名"], 动作: "set", 值: "新名" }]);
});
// @muse-case {"case_id":"NC-form-projection-refresh","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"原缓冲包含现已隐藏的字段","when":"使用新的服务器投影","then":["移除不允许显示的旧值,保留仍可编辑的输入"],"contract":"docs/系统架构/新版设计/接口契约/元数据投影与版本.md"}
it("NC-form-projection-refresh:新投影清除不允许显示的旧输入", () => {
const schema = { type: "object", properties: { 公开: { type: "string" } } };
expect(投影表单值(schema, { 公开: "保留", 秘密: "旧输入" })).toEqual({
公开: "保留",
});
expect(生成字段修改({ 公开: "旧值" }, { 公开: "保留" }, schema)).toEqual([
{ 路径: ["公开"], 动作: "set", 值: "保留" },
]);
});