import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; function readSource(path: string): string { return readFileSync(new URL(`../${path}`, import.meta.url), "utf8"); } describe("settings form actions", () => { // 各资源页的头部 New 按钮已统一由 SettingsResourceHeaderActions 渲染,尺寸约束随之 // 移到该共享组件;这里改为在真实位置断言尺寸,并确认子智能体页确实走同一组件。 it("列表头部 New 按钮统一由共享组件渲染", () => { const actions = readSource("src/settings/SettingsResourceHeaderActions.tsx"); expect(actions).toMatch( /size="default"\s+className="rounded-lg"\s+data-settings-create-action=\{newActionId\}\s+aria-label=\{newLabel\}/, ); expect(readSource("src/settings/SubagentsSection.tsx")).toContain( " { const source = readSource(`src/settings/${file}`); expect(source).toContain(" { const source = readSource(`src/settings/${file}`); expect(source.split('id: "common.save"').length - 1).toBe(1); }); it("新建和编辑 MCP 都使用保存文案", () => { const source = readSource("src/settings/McpServerForm.tsx"); expect(source).toContain('id: "common.save"'); expect(source).not.toContain('id: "settings.mcp.form.add"'); }); it("操作栏始终把取消与保存放到右侧", () => { const source = readSource("src/settings/SettingsFormActions.tsx"); expect(source).toContain("sm:ml-auto"); expect(source).toContain("justify-end"); }); it.each([ "McpServerForm.tsx", "CommandForm.tsx", "HookForm.tsx", "SubagentsSection.tsx", ])("统一 %s 的保存可用状态", (file) => { const source = readSource(`src/settings/${file}`); expect(source).toContain("const canSave ="); expect(source).toMatch(/disabled=\{[^}]*!canSave/); }); it("子智能体的保存判定属于编辑表单", () => { const source = readSource("src/settings/SubagentsSection.tsx"); const formSource = source.slice(source.indexOf("function SubagentForm(")); expect(formSource).toContain("const canSave ="); expect(formSource).toContain("disabled={!canSave || saving}"); }); });