// @vitest-environment jsdom // 子代理药丸(docs/dynamic-workflow/presentation.md「The pill」):可打开时整枚是按钮, // 悬停语法挂在 wf-pill-open 上、↗ 是可见证据;不可打开时是 span,inertTitle 解释为什么。 import { cleanup, fireEvent, render } from "@testing-library/react"; import { createElement } from "react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js"; import { WorkflowAgentPill, avatarColor, } from "@/components/workflow-timeline/WorkflowAgentPill.js"; afterEach(() => { cleanup(); }); function renderPill(props: Parameters[0]) { return render( createElement( ZCodeIntlProvider, { initialLocale: "en-US" }, createElement(WorkflowAgentPill, props), ), ); } function view_state(props: { status: Parameters[0]["status"] }) { const view = renderPill({ laneClass: "agent", name: "Ada", avatarIndex: 0, ...props }); const state = view.container .querySelector("svg[data-subagent-avatar]")! .getAttribute("data-face-state"); view.unmount(); return state; } describe("WorkflowAgentPill", () => { it("前九个编号的脸色相互不相同,第十个循环;表情读 status", () => { const hues = Array.from({ length: 10 }, (_, avatarIndex) => { const view = renderPill({ laneClass: "agent", name: "same", avatarIndex, status: "done" }); const face = view.container.querySelector("svg[data-subagent-avatar]") as SVGSVGElement; expect(face.getAttribute("data-face-state")).toBe("content"); const hue = face.style.getPropertyValue("--wf-face-body"); view.unmount(); return hue; }); expect(new Set(hues.slice(0, 9)).size).toBe(9); expect(hues[9]).toBe(hues[0]); expect(view_state({ status: undefined })).toBe("waiting"); expect(view_state({ status: "running" })).toBe("scanning"); expect(view_state({ status: "failed" })).toBe("sad"); }); it("可打开: