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

PullRequestsUnavailableState.test.tsx

32 lines1.2 KB

1import { isValidElement, type ReactElement, type ReactNode } from "react";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
5​
6function textOf(node: ReactNode): string {
7 if (typeof node === "string" || typeof node === "number") return String(node);
8 if (Array.isArray(node)) return node.map(textOf).join(" ");
9 if (!isValidElement(node)) return "";
10 return textOf((node as ReactElement<{ children?: ReactNode }>).props.children);
12​
13describe("PullRequestsUnavailableState", () => {
14 it("can explain an unsupported environment without offering a futile retry", () => {
15 const text = textOf(
16 PullRequestsUnavailableState({
17 title: "Pull requests unavailable",
18 error: "Update this environment's T3 Code server to browse pull requests.",
19 }),
20 );
21​
22 expect(text).toContain("Pull requests unavailable");
23 expect(text).toContain("Update this environment's T3 Code server");
24 expect(text).not.toContain("Retry");
25 });
26​
27 it("retains the retry for transient load failures", () => {
28 expect(
29 textOf(PullRequestsUnavailableState({ error: "GitHub did not answer.", onRetry: () => {} })),
30 ).toContain("Retry");
31 });
32});