Open History to see the last commit
1import { isValidElement, type ReactElement, type ReactNode } from "react";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
6
7function textOf(node: ReactNode): string {
8 if (typeof node === "string" || typeof node === "number") return String(node);
9 if (Array.isArray(node)) return node.map(textOf).join(" ");
10 if (!isValidElement(node)) return "";
11 return textOf((node as ReactElement<{ children?: ReactNode }>).props.children);
12}
13
14describe("PullRequestsUnavailableState", () => {
15 it("can explain an unsupported environment without offering a futile retry", () => {
16 const text = textOf(
17 PullRequestsUnavailableState({
18 title: "Pull requests unavailable",
19 error: "Update this environment's T3 Code server to browse pull requests.",
20 }),
21 );
22
23 expect(text).toContain("Pull requests unavailable");
24 expect(text).toContain("Update this environment's T3 Code server");
25 expect(text).not.toContain("Retry");
26 });
27
28 it("retains the retry for transient load failures", () => {
29 const html = renderToStaticMarkup(
30 <PullRequestsUnavailableState
31 error="GitHub did not answer."
32 onRetry={() => {}}
33 gitHubUrl="https://github.com/pingdotgg/t3code/pull/42"
34 />,
35 );
36
37 expect(html).toContain("Retry");
38 expect(html).toContain("Open on GitHub");
39 expect(html).toContain('href="https://github.com/pingdotgg/t3code/pull/42"');
40 expect(html).toContain('target="_blank"');
41 expect(html).toContain('rel="noopener noreferrer"');
42 });
43
44 it("can offer the browser without offering a retry", () => {
45 const html = renderToStaticMarkup(
46 <PullRequestsUnavailableState
47 error="This server cannot read the pull request."
48 gitHubUrl="https://github.com/pingdotgg/t3code/pull/9"
49 />,
50 );
51
52 expect(html).toContain("Open on GitHub");
53 expect(html).not.toContain("Retry");
54 });
55
56 it("can offer a retry without offering GitHub", () => {
57 const html = renderToStaticMarkup(
58 <PullRequestsUnavailableState error="The host did not answer." onRetry={() => {}} />,
59 );
60
61 expect(html).toContain("Retry");
62 expect(html).not.toContain("Open on GitHub");
63 });
64
65 it("renders no action content without a retry or browser target", () => {
66 const html = renderToStaticMarkup(
67 <PullRequestsUnavailableState error="This project has no known remote." />,
68 );
69
70 expect(html).not.toContain('data-slot="empty-content"');
71 expect(html).not.toContain("href=");
72 });
73});