Open History to see the last commit
1import type { VcsStatusResult } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 prStatusIndicator,
6 resolveThreadPr,
7 settledPrHoverColorClass,
8} from "./ThreadStatusIndicators";
9
10function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
11 return {
12 isRepo: true,
13 hasPrimaryRemote: true,
14 isDefaultRef: false,
15 refName: "feature/current",
16 hasWorkingTreeChanges: false,
17 workingTree: { files: [], insertions: 0, deletions: 0 },
18 hasUpstream: true,
19 aheadCount: 0,
20 behindCount: 0,
21 pr: {
22 number: 42,
23 title: "PR branch",
24 url: "https://github.com/pingdotgg/t3code/pull/42",
25 baseRef: "main",
26 headRef: "feature/current",
27 state: "open",
28 },
29 ...overrides,
30 };
31}
32
33describe("resolveThreadPr", () => {
34 it("keeps local-checkout PR indicators scoped to the stored thread branch", () => {
35 expect(
36 resolveThreadPr({
37 threadBranch: "feature/other",
38 gitStatus: status(),
39 hasDedicatedWorktree: false,
40 }),
41 ).toBeNull();
42 });
43
44 it("shows PR indicators for dedicated worktree threads even when branch metadata is stale", () => {
45 const gitStatus = status();
46
47 expect(
48 resolveThreadPr({
49 threadBranch: "feature/old-name",
50 gitStatus,
51 hasDedicatedWorktree: true,
52 }),
53 ).toBe(gitStatus.pr);
54 });
55
56 it("shows PR indicators for dedicated worktree threads even when branch metadata is missing", () => {
57 const gitStatus = status();
58
59 expect(
60 resolveThreadPr({
61 threadBranch: null,
62 gitStatus,
63 hasDedicatedWorktree: true,
64 }),
65 ).toBe(gitStatus.pr);
66 });
67});
68
69describe("prStatusIndicator", () => {
70 it("formats PR tooltips with number, uppercase status, and title", () => {
71 expect(prStatusIndicator(status().pr, undefined)).toMatchObject({
72 tooltip: "PR #42 - Open: PR branch",
73 tooltipLead: "PR #42 - Open",
74 tooltipTitle: "PR branch",
75 });
76 });
77
78 it("uses red for closed pull requests", () => {
79 const closedPr = status().pr;
80 if (!closedPr) throw new Error("Expected pull request fixture");
81
82 expect(prStatusIndicator({ ...closedPr, state: "closed" }, undefined)?.colorClass).toContain(
83 "text-red-600",
84 );
85 });
86});
87
88describe("settledPrHoverColorClass", () => {
89 it.each([
90 ["open", "text-emerald-600"],
91 ["merged", "text-violet-600"],
92 ["closed", "text-red-600"],
93 ] as const)("restores the %s pull request color on row hover", (state, colorClass) => {
94 expect(settledPrHoverColorClass(state)).toContain(`group-hover/v2-row:${colorClass}`);
95 });
96});