Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerPendingApprovalActions.test.tsx

83 lines2.9 KB

1import { ApprovalRequestId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
6​
7describe("ComposerPendingApprovalActions", () => {
8 it("states that the persistent approval lasts for this session", () => {
9 const markup = renderToStaticMarkup(
10 <ComposerPendingApprovalActions
11 requestId={ApprovalRequestId.make("approval-1")}
12 isResponding={false}
13 onRespondToApproval={async () => undefined}
14 />,
15 );
16​
17 expect(markup).toContain(">Cancel<");
18 expect(markup).toContain("Always allow this session");
19 expect(markup).not.toContain(">Always allow<");
20 expect(markup).toContain("h-5");
21 expect(markup).toContain("sm:text-[11px]");
22 expect(markup).not.toContain("sm:h-6");
23 });
24​
25 it("shows only the approval choices advertised by an MCP server", () => {
26 const markup = renderToStaticMarkup(
27 <ComposerPendingApprovalActions
28 requestId={ApprovalRequestId.make("approval-safari")}
29 isResponding={false}
30 options={[
31 { decision: "decline", label: "Decline" },
32 { decision: "acceptAlways", label: "Always allow Safari" },
33 { decision: "accept", label: "Approve" },
34 ]}
35 onRespondToApproval={async () => undefined}
36 />,
37 );
38​
39 expect(markup).toContain("Always allow Safari");
40 expect(markup).toContain(">Approve<");
41 expect(markup).not.toContain("Always allow this session");
42 });
43​
44 it("marks an option that carries a provider warning", () => {
45 const markup = renderToStaticMarkup(
46 <ComposerPendingApprovalActions
47 requestId={ApprovalRequestId.make("approval-1")}
48 isResponding={false}
49 options={[
50 { decision: "accept", label: "Allow once" },
51 {
52 decision: "acceptForSession",
53 label: "Allow for this thread",
54 warning: "Untrusted files could re-run this action without asking.",
55 },
56 { decision: "decline", label: "Deny" },
57 ]}
58 onRespondToApproval={async () => undefined}
59 />,
60 );
61​
62 expect(markup).toContain(
63 'aria-description="Untrusted files could re-run this action without asking."',
64 );
65 expect(markup).toContain("text-warning");
66 expect(markup).toContain("Allow for this thread");
67 });
68​
69 it("limits provider-supplied approval labels so narrow rows can wrap", () => {
70 const label = "Allow ".repeat(40).trim();
71 const markup = renderToStaticMarkup(
72 <ComposerPendingApprovalActions
73 requestId={ApprovalRequestId.make("approval-long-label")}
74 isResponding={false}
75 options={[{ decision: "acceptAlways", label }]}
76 onRespondToApproval={async () => undefined}
77 />,
78 );
79​
80 expect(markup).toContain('class="max-w-40 truncate"');
81 expect(markup).toContain(label);
82 });
83});