Open History to see the last commit
1import type { VcsStatusResult } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { prStatusIndicator, resolveThreadPr } from "./ThreadStatusIndicators";
5
6function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
7 return {
8 isRepo: true,
9 hasPrimaryRemote: true,
10 isDefaultRef: false,
11 refName: "feature/current",
12 hasWorkingTreeChanges: false,
13 workingTree: { files: [], insertions: 0, deletions: 0 },
14 hasUpstream: true,
15 aheadCount: 0,
16 behindCount: 0,
17 pr: {
18 number: 42,
19 title: "PR branch",
20 url: "https://github.com/pingdotgg/t3code/pull/42",
21 baseRef: "main",
22 headRef: "feature/current",
23 state: "open",
24 },
25 ...overrides,
26 };
27}
28
29describe("resolveThreadPr", () => {
30 it("keeps local-checkout PR indicators scoped to the stored thread branch", () => {
31 expect(
32 resolveThreadPr({
33 threadBranch: "feature/other",
34 gitStatus: status(),
35 hasDedicatedWorktree: false,
36 }),
37 ).toBeNull();
38 });
39
40 it("shows PR indicators for dedicated worktree threads even when branch metadata is stale", () => {
41 const gitStatus = status();
42
43 expect(
44 resolveThreadPr({
45 threadBranch: "feature/old-name",
46 gitStatus,
47 hasDedicatedWorktree: true,
48 }),
49 ).toBe(gitStatus.pr);
50 });
51
52 it("shows PR indicators for dedicated worktree threads even when branch metadata is missing", () => {
53 const gitStatus = status();
54
55 expect(
56 resolveThreadPr({
57 threadBranch: null,
58 gitStatus,
59 hasDedicatedWorktree: true,
60 }),
61 ).toBe(gitStatus.pr);
62 });
63});
64
65describe("prStatusIndicator", () => {
66 it("formats PR tooltips with number, uppercase status, and title", () => {
67 expect(prStatusIndicator(status().pr, undefined)).toMatchObject({
68 tooltip: "PR #42 - Open: PR branch",
69 tooltipLead: "PR #42 - Open",
70 tooltipTitle: "PR branch",
71 });
72 });
73});