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

ThreadStatusIndicators.test.ts

100 lines2.7 KB

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 };
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 }),
40 ).toBeNull();
41 });
42​
43 it("hides PR indicators when a dedicated worktree has switched away from the thread branch", () => {
44 expect(
45 resolveThreadPr({
46 threadBranch: "stack/base",
47 gitStatus: status(),
48 }),
49 ).toBeNull();
50 });
51​
52 it("hides PR indicators when thread branch metadata is missing", () => {
53 expect(
54 resolveThreadPr({
55 threadBranch: null,
56 gitStatus: status(),
57 }),
58 ).toBeNull();
59 });
60​
61 it("shows the PR when the live checkout matches the stored thread branch", () => {
62 const gitStatus = status();
63​
64 expect(
65 resolveThreadPr({
66 threadBranch: "feature/current",
67 gitStatus,
68 }),
69 ).toBe(gitStatus.pr);
70 });
71});
72​
73describe("prStatusIndicator", () => {
74 it("formats PR tooltips with number, uppercase status, and title", () => {
75 expect(prStatusIndicator(status().pr, undefined)).toMatchObject({
76 tooltip: "PR #42 - Open: PR branch",
77 tooltipLead: "PR #42 - Open",
78 tooltipTitle: "PR branch",
79 });
80 });
81​
82 it("uses red for closed pull requests", () => {
83 const closedPr = status().pr;
84 if (!closedPr) throw new Error("Expected pull request fixture");
85​
86 expect(prStatusIndicator({ ...closedPr, state: "closed" }, undefined)?.colorClass).toContain(
87 "text-red-600",
88 );
89 });
90});
91​
92describe("settledPrHoverColorClass", () => {
93 it.each([
94 ["open", "text-emerald-600"],
95 ["merged", "text-violet-600"],
96 ["closed", "text-red-600"],
97 ] as const)("restores the %s pull request color on row hover", (state, colorClass) => {
98 expect(settledPrHoverColorClass(state)).toContain(`group-hover/v2-row:${colorClass}`);
99 });
100});