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

ThreadStatusIndicators.test.ts

136 lines4.3 KB

1import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import {
4 GitMergeIcon,
5 GitPullRequestClosedIcon,
6 GitPullRequestDraftIcon,
7 GitPullRequestIcon,
8} from "lucide-react";
9​
10import {
11 ChangeRequestStatusIcon,
12 prStatusIndicator,
13 settledPrHoverColorClass,
14} from "./ThreadStatusIndicators";
15import { newestPullRequestSummary } from "../state/pullRequests";
16​
17describe("ChangeRequestStatusIcon", () => {
18 it.each([
19 ["open", "open", false, GitPullRequestIcon],
20 ["draft", "open", true, GitPullRequestDraftIcon],
21 ["closed", "closed", false, GitPullRequestClosedIcon],
22 ["merged", "merged", false, GitMergeIcon],
23 ] as const)("uses the %s pull request glyph", (_label, state, isDraft, expectedIcon) => {
24 expect(ChangeRequestStatusIcon({ state, isDraft }).type).toBe(expectedIcon);
25 });
26});
27​
28function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
29 return {
30 isRepo: true,
31 hasPrimaryRemote: true,
32 isDefaultRef: false,
33 refName: "feature/current",
34 hasWorkingTreeChanges: false,
35 workingTree: { files: [], insertions: 0, deletions: 0 },
36 hasUpstream: true,
37 aheadCount: 0,
38 behindCount: 0,
39 pr: {
40 number: 42,
41 title: "PR branch",
42 url: "https://github.com/pingdotgg/t3code/pull/42",
43 baseRef: "main",
44 headRef: "feature/current",
45 state: "open",
46 },
47 ...overrides,
48 };
50​
51function pullRequestSummary(
52 state: PullRequestSummary["state"],
53 updatedAt: string,
54): PullRequestSummary {
55 return {
56 provider: "github",
57 projectId: ProjectId.make("project-1"),
58 repository: "pingdotgg/t3code",
59 number: 42,
60 title: "Feature PR",
61 url: "https://github.com/pingdotgg/t3code/pull/42",
62 state,
63 headBranch: "feature/current",
64 baseBranch: "main",
65 updatedAt,
66 };
68​
69describe("shared pull request state", () => {
70 it("shows a panel-observed merge instead of an older sidebar summary", () => {
71 const open = pullRequestSummary("open", "2026-09-03T01:00:00.000Z");
72 const merged = pullRequestSummary("merged", "2026-09-03T01:01:00.000Z");
73​
74 expect(newestPullRequestSummary(open, merged)).toBe(merged);
75 });
76​
77 it("never lets a stale open response regress a merged observation", () => {
78 const merged = pullRequestSummary("merged", "2026-09-03T01:01:00.000Z");
79 const staleOpen = pullRequestSummary("open", "2026-09-03T01:00:00.000Z");
80​
81 expect(newestPullRequestSummary(merged, staleOpen)).toBe(merged);
82 });
83​
84 it("accepts a newer open state after a closed pull request is reopened", () => {
85 const closed = pullRequestSummary("closed", "2026-09-03T01:00:00.000Z");
86 const reopened = pullRequestSummary("open", "2026-09-03T01:01:00.000Z");
87​
88 expect(newestPullRequestSummary(closed, reopened)).toBe(reopened);
89 });
90});
91​
92describe("prStatusIndicator", () => {
93 it("formats PR tooltips with number, uppercase status, and title", () => {
94 expect(prStatusIndicator(status().pr, undefined)).toMatchObject({
95 tooltip: "PR #42 - Open: PR branch",
96 tooltipLead: "PR #42 - Open",
97 tooltipTitle: "PR branch",
98 });
99 });
100​
101 it("uses red for closed pull requests", () => {
102 const closedPr = status().pr;
103 if (!closedPr) throw new Error("Expected pull request fixture");
104​
105 expect(prStatusIndicator({ ...closedPr, state: "closed" }, undefined)?.colorClass).toContain(
106 "text-red-600",
107 );
108 });
109​
110 it("uses gray and draft wording for draft pull requests", () => {
111 const draftPr = status().pr;
112 if (!draftPr) throw new Error("Expected pull request fixture");
113​
114 expect(prStatusIndicator({ ...draftPr, isDraft: true }, undefined)).toMatchObject({
115 label: "PR draft",
116 colorClass: "text-zinc-500 dark:text-zinc-400/80",
117 tooltipLead: "PR #42 - Draft",
118 });
119 });
120});
121​
122describe("settledPrHoverColorClass", () => {
123 it.each([
124 ["open", "text-emerald-600"],
125 ["merged", "text-violet-600"],
126 ["closed", "text-red-600"],
127 ] as const)("restores the %s pull request color on row hover", (state, colorClass) => {
128 expect(settledPrHoverColorClass(state)).toContain(`group-hover/sidebar-row:${colorClass}`);
129 });
130​
131 it("keeps draft pull requests gray on row hover", () => {
132 expect(settledPrHoverColorClass("open", true)).toContain(
133 "group-hover/sidebar-row:text-zinc-500",
134 );
135 });
136});