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

ProviderStatusBanner.test.tsx

155 lines5.0 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4​
5import {
6 getProviderStatusBannerKey,
7 getProviderStatusMessage,
8 ProviderStatusBanner,
9 shouldShowProviderStatusBanner,
10} from "./ProviderStatusBanner";
11​
12function warningProvider(): ServerProvider {
13 return {
14 instanceId: ProviderInstanceId.make("codex"),
15 driver: ProviderDriverKind.make("codex"),
16 displayName: "Codex",
17 enabled: true,
18 installed: true,
19 version: "1.0.0",
20 status: "warning",
21 auth: { status: "authenticated" },
22 checkedAt: "2026-07-23T12:00:00.000Z",
23 message: "Provider is temporarily degraded.",
24 models: [],
25 slashCommands: [],
26 skills: [],
27 };
29​
30describe("ProviderStatusBanner", () => {
31 it("waits for an Antigravity auth result before showing a sign-in warning", () => {
32 const status: ServerProvider = {
33 ...warningProvider(),
34 instanceId: ProviderInstanceId.make("google_work"),
35 driver: ProviderDriverKind.make("antigravity"),
36 auth: { status: "unknown" },
37 message: "Antigravity is installed. Google account access is not checked yet.",
38 };
39​
40 expect(shouldShowProviderStatusBanner(status, null)).toBe(false);
41 expect(
42 shouldShowProviderStatusBanner(
43 {
44 ...status,
45 auth: { status: "unauthenticated" },
46 message: "Sign in with Google to use Antigravity.",
47 },
48 null,
49 ),
50 ).toBe(true);
51 });
52​
53 it("shows Antigravity installation and startup failures before auth is checked", () => {
54 const status: ServerProvider = {
55 ...warningProvider(),
56 driver: ProviderDriverKind.make("antigravity"),
57 auth: { status: "unknown" },
58 };
59​
60 expect(shouldShowProviderStatusBanner({ ...status, installed: false }, null)).toBe(true);
61 expect(shouldShowProviderStatusBanner({ ...status, status: "error" }, null)).toBe(true);
62 expect(
63 shouldShowProviderStatusBanner({ ...status, driver: ProviderDriverKind.make("codex") }, null),
64 ).toBe(true);
65 });
66​
67 it("stays hidden after its current warning is dismissed", () => {
68 const status = warningProvider();
69​
70 expect(shouldShowProviderStatusBanner(status, null)).toBe(true);
71 expect(shouldShowProviderStatusBanner(status, getProviderStatusBannerKey(status))).toBe(false);
72 });
73​
74 it("renders an accessible dismiss control for provider warnings", () => {
75 const markup = renderToStaticMarkup(
76 <ProviderStatusBanner status={warningProvider()} onDismiss={() => {}} />,
77 );
78​
79 expect(markup).toContain('role="alert"');
80 expect(markup).toContain('aria-label="Dismiss Codex provider warning"');
81 expect(markup).toContain("absolute top-2 right-2");
82 });
83​
84 it("renders on a glass surface so the timeline never reads through the banner", () => {
85 const markup = renderToStaticMarkup(
86 <ProviderStatusBanner status={warningProvider()} onDismiss={() => {}} />,
87 );
88​
89 expect(markup).toContain("alert-glass");
90 expect(markup).toContain('data-variant="warning"');
91 });
92​
93 it("labels error dismiss controls with the correct severity", () => {
94 const markup = renderToStaticMarkup(
95 <ProviderStatusBanner
96 status={{ ...warningProvider(), status: "error" }}
97 onDismiss={() => {}}
98 />,
99 );
100​
101 expect(markup).toContain('aria-label="Dismiss Codex provider error"');
102 });
103});
104​
105describe("getProviderStatusMessage", () => {
106 it("preserves the environment's authentication error", () => {
107 const message = "SUBSCRIPTION_REQUIRED: This Google account cannot use Antigravity.";
108 expect(
109 getProviderStatusMessage({
110 ...warningProvider(),
111 driver: ProviderDriverKind.make("antigravity"),
112 status: "error",
113 auth: { status: "unauthenticated" },
114 message,
115 }),
116 ).toBe(message);
117 });
118​
119 it("points a signed-out Antigravity account to Google sign-in without a CLI command", () => {
120 expect(
121 getProviderStatusMessage({
122 ...warningProvider(),
123 driver: ProviderDriverKind.make("antigravity"),
124 status: "error",
125 auth: { status: "unauthenticated" },
126 message: "",
127 }),
128 ).toBe("Open provider setup to sign in with Google.");
129 });
130​
131 it("requires installation on the environment before sign-in", () => {
132 expect(
133 getProviderStatusMessage({
134 ...warningProvider(),
135 driver: ProviderDriverKind.make("antigravity"),
136 displayName: "Google work account",
137 installed: false,
138 status: "error",
139 auth: { status: "unauthenticated" },
140 message: "",
141 }),
142 ).toBe("Open provider setup to install Antigravity on this environment.");
143 });
144​
145 it("keeps CLI sign-in advice for a provider without integrated setup", () => {
146 expect(
147 getProviderStatusMessage({
148 ...warningProvider(),
149 status: "error",
150 auth: { status: "unauthenticated" },
151 message: "",
152 }),
153 ).toBe("Sign in via the CLI to authenticate again.");
154 });
155});