// @vitest-environment node import { describe, expect, it } from "vitest"; import { renderToStaticMarkup } from "react-dom/server"; import type { ActivityEvent } from "@paperclipai/shared"; import { IssueFieldChangeReceipt } from "./IssueFieldChangeReceipt"; function event(overrides: Partial = {}) { return { action: "issue.updated", details: null, responsibleUserId: null, ...overrides, } as Pick; } describe("IssueFieldChangeReceipt", () => { it("shows before and after for each changed field", () => { const html = renderToStaticMarkup( , ); expect(html).toContain("Status"); expect(html).toContain("todo"); expect(html).toContain("in progress"); expect(html).toContain("Priority"); expect(html).toContain("high"); expect(html).toContain('data-testid="issue-change-row-status"'); }); it("names the responsible user and the authorization reason", () => { const html = renderToStaticMarkup( "Dotta"} />, ); expect(html).toContain("Dotta"); expect(html).toContain("authorized by default-open write on a visible task"); }); it("resolves an assignee change to agent names", () => { const html = renderToStaticMarkup( id.startsWith("3108") ? "ClaudeCoder" : "UXDesigner"} />, ); expect(html).toContain("Assignee"); expect(html).toContain("ClaudeCoder"); expect(html).toContain("UXDesigner"); }); it("marks server-truncated long text as a preview", () => { const html = renderToStaticMarkup( , ); expect(html).toContain("Description"); expect(html).toContain("preview"); }); it("renders a board edit's receipt the same way as an agent's", () => { // Plan ยง3b: audit is required for human PATCHes too, not only agent ones. const html = renderToStaticMarkup( , ); expect(html).toContain("Title"); expect(html).toContain("authorized by board actor"); }); it("renders nothing for events with no receipt", () => { expect(renderToStaticMarkup()).toBe(""); // Pre-receipt rows carried loose fields but no `changes` receipt. expect(renderToStaticMarkup( , )).toBe(""); }); it("still explains authorization when only a reason was recorded", () => { const html = renderToStaticMarkup( , ); expect(html).toContain("authorized by own task"); }); });