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

ProviderStatusBanner.test.tsx

119 lines3.7 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("stays hidden after its current warning is dismissed", () => {
32 const status = warningProvider();
33​
34 expect(shouldShowProviderStatusBanner(status, null)).toBe(true);
35 expect(shouldShowProviderStatusBanner(status, getProviderStatusBannerKey(status))).toBe(false);
36 });
37​
38 it("renders an accessible dismiss control for provider warnings", () => {
39 const markup = renderToStaticMarkup(
40 <ProviderStatusBanner status={warningProvider()} onDismiss={() => {}} />,
41 );
42​
43 expect(markup).toContain('role="alert"');
44 expect(markup).toContain('aria-label="Dismiss Codex provider warning"');
45 expect(markup).toContain("absolute top-2 right-2");
46 });
47​
48 it("renders on a glass surface so the timeline never reads through the banner", () => {
49 const markup = renderToStaticMarkup(
50 <ProviderStatusBanner status={warningProvider()} onDismiss={() => {}} />,
51 );
52​
53 expect(markup).toContain("alert-glass");
54 expect(markup).toContain('data-variant="warning"');
55 });
56​
57 it("labels error dismiss controls with the correct severity", () => {
58 const markup = renderToStaticMarkup(
59 <ProviderStatusBanner
60 status={{ ...warningProvider(), status: "error" }}
61 onDismiss={() => {}}
62 />,
63 );
64​
65 expect(markup).toContain('aria-label="Dismiss Codex provider error"');
66 });
67});
68​
69describe("getProviderStatusMessage", () => {
70 it("preserves the environment's authentication error", () => {
71 const message = "SUBSCRIPTION_REQUIRED: This Google account cannot use Antigravity.";
72 expect(
73 getProviderStatusMessage({
74 ...warningProvider(),
75 driver: ProviderDriverKind.make("antigravity"),
76 status: "error",
77 auth: { status: "unauthenticated" },
78 message,
79 }),
80 ).toBe(message);
81 });
82​
83 it("points a signed-out Antigravity account to Google sign-in without a CLI command", () => {
84 expect(
85 getProviderStatusMessage({
86 ...warningProvider(),
87 driver: ProviderDriverKind.make("antigravity"),
88 status: "error",
89 auth: { status: "unauthenticated" },
90 message: "",
91 }),
92 ).toBe("Open provider setup to sign in with Google.");
93 });
94​
95 it("requires installation on the environment before sign-in", () => {
96 expect(
97 getProviderStatusMessage({
98 ...warningProvider(),
99 driver: ProviderDriverKind.make("antigravity"),
100 displayName: "Google work account",
101 installed: false,
102 status: "error",
103 auth: { status: "unauthenticated" },
104 message: "",
105 }),
106 ).toBe("Open provider setup to install Antigravity on this environment.");
107 });
108​
109 it("keeps CLI sign-in advice for a provider without integrated setup", () => {
110 expect(
111 getProviderStatusMessage({
112 ...warningProvider(),
113 status: "error",
114 auth: { status: "unauthenticated" },
115 message: "",
116 }),
117 ).toBe("Sign in via the CLI to authenticate again.");
118 });
119});