1import { RuntimeRequestId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
6
7describe("ComposerPendingApprovalPanel", () => {
8 it("keeps the complete command readable in the compact row", () => {
9 const detail = `bun run release -- ${"x".repeat(500)}\nsecond line`;
10 const markup = renderToStaticMarkup(
11 <ComposerPendingApprovalPanel
12 approval={{
13 requestId: RuntimeRequestId.make("approval-1"),
14 requestKind: "command",
15 createdAt: "2026-07-18T00:00:00.000Z",
16 detail,
17 responseCapability: "live",
18 }}
19 pendingCount={1}
20 />,
21 );
22
23 expect(markup).toContain(detail);
24 expect(markup).not.toContain("Command approval requested");
25 });
26
27 it("falls back to the approval kind when the provider sends an empty detail", () => {
28 const markup = renderToStaticMarkup(
29 <ComposerPendingApprovalPanel
30 approval={{
31 requestId: RuntimeRequestId.make("approval-2"),
32 requestKind: "file-read",
33 responseCapability: "live" as const,
34 createdAt: "2026-07-18T00:00:00.000Z",
35 detail: "",
36 }}
37 pendingCount={1}
38 />,
39 );
40
41 expect(markup).toContain("File read approval");
42 });
43
44 it("shows the app name and message for an MCP access request", () => {
45 const markup = renderToStaticMarkup(
46 <ComposerPendingApprovalPanel
47 approval={{
48 requestId: RuntimeRequestId.make("approval-safari"),
49 requestKind: "mcp-elicitation",
50 responseCapability: "live" as const,
51 createdAt: "2026-08-24T00:00:00.000Z",
52 appName: "Safari",
53 detail: "Allow ChatGPT to use Safari?",
54 }}
55 pendingCount={1}
56 />,
57 );
58
59 expect(markup).toContain(">Safari<");
60 expect(markup).toContain("Allow ChatGPT to use Safari?");
61 });
62
63 it("preserves the full app name and approval message", () => {
64 const appName = "A".repeat(200);
65 const detail = "Allow ChatGPT to access the selected application?";
66 const markup = renderToStaticMarkup(
67 <ComposerPendingApprovalPanel
68 approval={{
69 requestId: RuntimeRequestId.make("approval-long-app-name"),
70 requestKind: "mcp-elicitation",
71 responseCapability: "live" as const,
72 createdAt: "2026-08-24T00:00:00.000Z",
73 appName,
74 detail,
75 }}
76 pendingCount={1}
77 />,
78 );
79
80 expect(markup).toContain(appName);
81 expect(markup).toContain(detail);
82 });
83});