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

ThreadStatusIndicators.test.ts

788 lines23.8 KB

1import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import { AtomRegistry } from "effect/unstable/reactivity";
5​
6import {
7 ChangeRequestStatusIcon,
8 nextThreadChangeRequestSnapshot,
9 prStatusIndicator,
10 resolveDisplayedThreadPr,
11 resolveDisplayedThreadPrProvider,
12 resolveThreadPr,
13 threadChangeRequestSnapshotsEqual,
14 threadChangeRequestSnapshotsAtom,
15 type ThreadChangeRequestSnapshot,
16 resolveThreadPullRequestBadgePresentation,
17} from "./ThreadStatusIndicators";
18import { newestPullRequestSummary } from "../state/pullRequests";
19import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
20​
21describe("ChangeRequestStatusIcon", () => {
22 it.each([
23 ["open", "open", false, PullRequestGlyph.pullRequest],
24 ["draft", "open", true, PullRequestGlyph.draft],
25 ["closed", "closed", false, PullRequestGlyph.closed],
26 ["merged", "merged", false, PullRequestGlyph.merged],
27 ] as const)("uses the %s pull request glyph", (_label, state, isDraft, expectedIcon) => {
28 expect(ChangeRequestStatusIcon({ state, isDraft }).type).toBe(expectedIcon);
29 });
30});
31​
32function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
33 return {
34 isRepo: true,
35 hasPrimaryRemote: true,
36 isDefaultRef: false,
37 refName: "feature/current",
38 hasWorkingTreeChanges: false,
39 workingTree: { files: [], insertions: 0, deletions: 0 },
40 hasUpstream: true,
41 aheadCount: 0,
42 behindCount: 0,
43 pr: {
44 number: 42,
45 title: "PR branch",
46 url: "https://github.com/pingdotgg/t3code/pull/42",
47 baseRef: "main",
48 headRef: "feature/current",
49 state: "open",
50 },
51 ...overrides,
52 };
54​
55function mergedFeaturePr(): NonNullable<VcsStatusResult["pr"]> {
56 return {
57 number: 42,
58 title: "Feature PR",
59 url: "https://github.com/pingdotgg/t3code/pull/42",
60 baseRef: "main",
61 headRef: "feature/current",
62 state: "merged",
63 };
65​
66function snapshotFor(
67 branch: string,
68 pr: NonNullable<VcsStatusResult["pr"]>,
69 sourceControlProvider?: VcsStatusResult["sourceControlProvider"],
70): ThreadChangeRequestSnapshot {
71 return { branch, pr, sourceControlProvider };
73​
74function pullRequestSummary(
75 state: PullRequestSummary["state"],
76 updatedAt: string,
77): PullRequestSummary {
78 return {
79 provider: "github",
80 projectId: ProjectId.make("project-1"),
81 repository: "pingdotgg/t3code",
82 number: 42,
83 title: "Feature PR",
84 url: "https://github.com/pingdotgg/t3code/pull/42",
85 state,
86 headBranch: "feature/current",
87 baseBranch: "main",
88 updatedAt,
89 };
91​
92describe("shared pull request state", () => {
93 it("shows a panel-observed merge instead of an older sidebar summary", () => {
94 const open = pullRequestSummary("open", "2026-09-03T01:00:00.000Z");
95 const merged = pullRequestSummary("merged", "2026-09-03T01:01:00.000Z");
96​
97 expect(newestPullRequestSummary(open, merged)).toBe(merged);
98 });
99​
100 it("never lets a stale open response regress a merged observation", () => {
101 const merged = pullRequestSummary("merged", "2026-09-03T01:01:00.000Z");
102 const staleOpen = pullRequestSummary("open", "2026-09-03T01:00:00.000Z");
103​
104 expect(newestPullRequestSummary(merged, staleOpen)).toBe(merged);
105 });
106​
107 it("accepts a newer open state after a closed pull request is reopened", () => {
108 const closed = pullRequestSummary("closed", "2026-09-03T01:00:00.000Z");
109 const reopened = pullRequestSummary("open", "2026-09-03T01:01:00.000Z");
110​
111 expect(newestPullRequestSummary(closed, reopened)).toBe(reopened);
112 });
113});
114​
115describe("resolveThreadPr", () => {
116 it("keeps local-checkout PR indicators scoped to the stored thread branch", () => {
117 expect(
118 resolveThreadPr({
119 threadBranch: "feature/other",
120 gitStatus: status(),
121 }),
122 ).toBeNull();
123 });
124​
125 it("hides PR indicators when a dedicated worktree has switched away from the thread branch", () => {
126 expect(
127 resolveThreadPr({
128 threadBranch: "stack/base",
129 gitStatus: status(),
130 }),
131 ).toBeNull();
132 });
133​
134 it("hides PR indicators when thread branch metadata is missing", () => {
135 expect(
136 resolveThreadPr({
137 threadBranch: null,
138 gitStatus: status(),
139 }),
140 ).toBeNull();
141 });
142​
143 it("shows the PR when the live checkout matches the stored thread branch", () => {
144 const gitStatus = status();
145​
146 expect(
147 resolveThreadPr({
148 threadBranch: "feature/current",
149 gitStatus,
150 }),
151 ).toBe(gitStatus.pr);
152 });
153});
154​
155describe("resolveDisplayedThreadPr + nextThreadChangeRequestSnapshot", () => {
156 const featureBranch = "feature/current";
157 const mergedPr = mergedFeaturePr();
158 const linkedPullRequest = {
159 projectId: ProjectId.make("project-1"),
160 repository: "pingdotgg/t3code",
161 number: 42,
162 url: "https://github.com/pingdotgg/t3code/pull/42",
163 };
164 const provider = {
165 kind: "github" as const,
166 name: "GitHub",
167 baseUrl: "https://github.com",
168 };
169​
170 it("returns the live merged PR when the checkout matches the feature branch", () => {
171 const gitStatus = status({
172 refName: featureBranch,
173 pr: mergedPr,
174 sourceControlProvider: provider,
175 });
176​
177 expect(
178 resolveDisplayedThreadPr({
179 threadBranch: featureBranch,
180 gitStatus,
181 snapshot: undefined,
182 retainTerminalOnBranchMismatch: true,
183 }),
184 ).toBe(mergedPr);
185 expect(
186 resolveDisplayedThreadPrProvider({
187 threadBranch: featureBranch,
188 gitStatus,
189 snapshot: undefined,
190 retainTerminalOnBranchMismatch: true,
191 }),
192 ).toEqual(provider);
193 });
194​
195 it("shows a linked pull request when the checkout has a different branch", () => {
196 const linkedPullRequestStatus = {
197 pr: mergedPr,
198 sourceControlProvider: provider,
199 };
200​
201 expect(
202 resolveDisplayedThreadPr({
203 threadBranch: "feature/other",
204 gitStatus: status({ refName: "feature/other", pr: null }),
205 snapshot: undefined,
206 retainTerminalOnBranchMismatch: false,
207 linkedPullRequest,
208 linkedPullRequestStatus,
209 }),
210 ).toEqual(mergedPr);
211 expect(
212 resolveDisplayedThreadPrProvider({
213 threadBranch: "feature/other",
214 gitStatus: status({ refName: "feature/other", pr: null }),
215 snapshot: undefined,
216 retainTerminalOnBranchMismatch: false,
217 linkedPullRequest,
218 linkedPullRequestStatus,
219 }),
220 ).toEqual(provider);
221 expect(
222 nextThreadChangeRequestSnapshot({
223 threadBranch: "feature/other",
224 gitStatus: status({ refName: "feature/other", pr: null }),
225 snapshot: undefined,
226 retainTerminalOnBranchMismatch: false,
227 linkedPullRequest,
228 linkedPullRequestStatus,
229 }),
230 ).toEqual({
231 branch: "feature/other",
232 pr: mergedPr,
233 sourceControlProvider: provider,
234 linkedPullRequest,
235 });
236 });
237​
238 it("keeps a matching linked pull request snapshot while its status reloads", () => {
239 const snapshot = {
240 ...snapshotFor(featureBranch, mergedPr, provider),
241 linkedPullRequest,
242 };
243​
244 expect(
245 resolveDisplayedThreadPr({
246 threadBranch: null,
247 gitStatus: null,
248 snapshot,
249 retainTerminalOnBranchMismatch: false,
250 linkedPullRequest,
251 linkedPullRequestStatus: null,
252 }),
253 ).toEqual(mergedPr);
254 expect(
255 nextThreadChangeRequestSnapshot({
256 threadBranch: null,
257 gitStatus: null,
258 snapshot,
259 retainTerminalOnBranchMismatch: false,
260 linkedPullRequest,
261 linkedPullRequestStatus: null,
262 }),
263 ).toBeUndefined();
264 });
265​
266 it("clears an old snapshot when a different pull request is linked", () => {
267 const snapshot = {
268 ...snapshotFor(featureBranch, mergedPr, provider),
269 linkedPullRequest: { ...linkedPullRequest, number: 41 },
270 };
271​
272 expect(
273 nextThreadChangeRequestSnapshot({
274 threadBranch: featureBranch,
275 gitStatus: null,
276 snapshot,
277 retainTerminalOnBranchMismatch: true,
278 linkedPullRequest,
279 linkedPullRequestStatus: null,
280 }),
281 ).toBeNull();
282 });
283​
284 it("removes a linked pull request snapshot after the link is cleared", () => {
285 const snapshot = {
286 ...snapshotFor(featureBranch, mergedPr, provider),
287 linkedPullRequest,
288 };
289​
290 expect(
291 resolveDisplayedThreadPr({
292 threadBranch: featureBranch,
293 gitStatus: status({ refName: "main", pr: null }),
294 snapshot,
295 retainTerminalOnBranchMismatch: true,
296 }),
297 ).toBeNull();
298 expect(
299 nextThreadChangeRequestSnapshot({
300 threadBranch: featureBranch,
301 gitStatus: null,
302 snapshot,
303 retainTerminalOnBranchMismatch: true,
304 }),
305 ).toBeNull();
306 });
307​
308 it("after caching a merged PR, resolves main status back to the cached feature PR", () => {
309 const matchingStatus = status({
310 refName: featureBranch,
311 pr: mergedPr,
312 sourceControlProvider: provider,
313 });
314 const cached = nextThreadChangeRequestSnapshot({
315 threadBranch: featureBranch,
316 gitStatus: matchingStatus,
317 snapshot: undefined,
318 retainTerminalOnBranchMismatch: true,
319 });
320 expect(cached).toEqual(snapshotFor(featureBranch, mergedPr, provider));
321​
322 const mainStatus = status({
323 refName: "main",
324 isDefaultRef: true,
325 pr: {
326 number: 99,
327 title: "Unrelated main PR",
328 url: "https://github.com/pingdotgg/t3code/pull/99",
329 baseRef: "main",
330 headRef: "main",
331 state: "open",
332 },
333 sourceControlProvider: provider,
334 });
335​
336 expect(
337 resolveDisplayedThreadPr({
338 threadBranch: featureBranch,
339 gitStatus: mainStatus,
340 snapshot: cached as ThreadChangeRequestSnapshot,
341 retainTerminalOnBranchMismatch: true,
342 }),
343 ).toEqual(mergedPr);
344 expect(
345 resolveDisplayedThreadPrProvider({
346 threadBranch: featureBranch,
347 gitStatus: mainStatus,
348 snapshot: cached as ThreadChangeRequestSnapshot,
349 retainTerminalOnBranchMismatch: true,
350 }),
351 ).toEqual(provider);
352 });
353​
354 it("never attaches a PR reported by main to the feature thread", () => {
355 const mainPr = {
356 number: 99,
357 title: "Unrelated main PR",
358 url: "https://github.com/pingdotgg/t3code/pull/99",
359 baseRef: "develop",
360 headRef: "main",
361 state: "merged" as const,
362 };
363 expect(
364 resolveDisplayedThreadPr({
365 threadBranch: featureBranch,
366 gitStatus: status({ refName: "main", pr: mainPr }),
367 snapshot: undefined,
368 retainTerminalOnBranchMismatch: true,
369 }),
370 ).toBeNull();
371 expect(
372 nextThreadChangeRequestSnapshot({
373 threadBranch: featureBranch,
374 gitStatus: status({ refName: "main", pr: mainPr }),
375 snapshot: undefined,
376 retainTerminalOnBranchMismatch: true,
377 }),
378 ).toBeNull();
379 });
380​
381 it("does not show a cached open PR across a branch mismatch", () => {
382 const openSnapshot = snapshotFor(featureBranch, {
383 ...mergedPr,
384 state: "open",
385 title: "Still open",
386 });
387​
388 expect(
389 resolveDisplayedThreadPr({
390 threadBranch: featureBranch,
391 gitStatus: status({ refName: "main", pr: null }),
392 snapshot: openSnapshot,
393 retainTerminalOnBranchMismatch: true,
394 }),
395 ).toBeNull();
396 });
397​
398 it("retains a cached closed PR across a branch mismatch", () => {
399 const closedPr = { ...mergedPr, state: "closed" as const, title: "Closed feature" };
400 const closedSnapshot = snapshotFor(featureBranch, closedPr, provider);
401​
402 expect(
403 resolveDisplayedThreadPr({
404 threadBranch: featureBranch,
405 gitStatus: status({ refName: "main", pr: null }),
406 snapshot: closedSnapshot,
407 retainTerminalOnBranchMismatch: true,
408 }),
409 ).toEqual(closedPr);
410 });
411​
412 it("does not retain or display a terminal PR when a worktree switches branches", () => {
413 const terminalSnapshot = snapshotFor(featureBranch, mergedPr, provider);
414 const mismatchedStatus = status({ refName: "feature/other", pr: null });
415​
416 expect(
417 resolveDisplayedThreadPr({
418 threadBranch: featureBranch,
419 gitStatus: mismatchedStatus,
420 snapshot: terminalSnapshot,
421 retainTerminalOnBranchMismatch: false,
422 }),
423 ).toBeNull();
424 expect(
425 resolveDisplayedThreadPrProvider({
426 threadBranch: featureBranch,
427 gitStatus: mismatchedStatus,
428 snapshot: terminalSnapshot,
429 retainTerminalOnBranchMismatch: false,
430 }),
431 ).toBeUndefined();
432 expect(
433 nextThreadChangeRequestSnapshot({
434 threadBranch: featureBranch,
435 gitStatus: mismatchedStatus,
436 snapshot: terminalSnapshot,
437 retainTerminalOnBranchMismatch: false,
438 }),
439 ).toBeNull();
440 });
441​
442 it("retains a local terminal snapshot when thread metadata follows the new branch", () => {
443 const otherBranchSnapshot = snapshotFor("feature/other", mergedPr, provider);
444​
445 expect(
446 resolveDisplayedThreadPr({
447 threadBranch: featureBranch,
448 gitStatus: status({ refName: "main", pr: null }),
449 snapshot: otherBranchSnapshot,
450 retainTerminalOnBranchMismatch: true,
451 }),
452 ).toEqual(mergedPr);
453 });
454​
455 it("retains a terminal snapshot when a local thread and status move to a branch with no PR", () => {
456 const terminalSnapshot = snapshotFor(featureBranch, mergedPr, provider);
457​
458 expect(
459 nextThreadChangeRequestSnapshot({
460 threadBranch: "main",
461 gitStatus: status({ refName: "main", pr: null }),
462 snapshot: terminalSnapshot,
463 retainTerminalOnBranchMismatch: true,
464 }),
465 ).toBeUndefined();
466 expect(
467 resolveDisplayedThreadPr({
468 threadBranch: "main",
469 gitStatus: status({ refName: "main", pr: null }),
470 snapshot: terminalSnapshot,
471 retainTerminalOnBranchMismatch: true,
472 }),
473 ).toEqual(mergedPr);
474 });
475​
476 it("clears an open snapshot when a local thread moves to a branch with no PR", () => {
477 const openSnapshot = snapshotFor(featureBranch, { ...mergedPr, state: "open" });
478​
479 expect(
480 nextThreadChangeRequestSnapshot({
481 threadBranch: "main",
482 gitStatus: status({ refName: "main", pr: null }),
483 snapshot: openSnapshot,
484 retainTerminalOnBranchMismatch: true,
485 }),
486 ).toBeNull();
487 });
488​
489 it("clears an open snapshot when a local checkout moves to a different branch", () => {
490 const openSnapshot = snapshotFor(featureBranch, { ...mergedPr, state: "open" });
491​
492 expect(
493 nextThreadChangeRequestSnapshot({
494 threadBranch: featureBranch,
495 gitStatus: status({ refName: "main", pr: null }),
496 snapshot: openSnapshot,
497 retainTerminalOnBranchMismatch: true,
498 }),
499 ).toBeNull();
500 });
501​
502 it("clears a retained snapshot when the thread branch is cleared", () => {
503 const terminalSnapshot = snapshotFor(featureBranch, mergedPr, provider);
504​
505 expect(
506 nextThreadChangeRequestSnapshot({
507 threadBranch: null,
508 gitStatus: status({ refName: "main", pr: null }),
509 snapshot: terminalSnapshot,
510 retainTerminalOnBranchMismatch: true,
511 }),
512 ).toBeNull();
513 expect(
514 resolveDisplayedThreadPr({
515 threadBranch: null,
516 gitStatus: status({ refName: "main", pr: null }),
517 snapshot: terminalSnapshot,
518 retainTerminalOnBranchMismatch: true,
519 }),
520 ).toBeNull();
521 expect(
522 resolveDisplayedThreadPrProvider({
523 threadBranch: null,
524 gitStatus: status({ refName: "main", pr: null }),
525 snapshot: terminalSnapshot,
526 retainTerminalOnBranchMismatch: true,
527 }),
528 ).toBeUndefined();
529 });
530​
531 it("does not erase a terminal snapshot when VCS data is missing", () => {
532 const terminalSnapshot = snapshotFor(featureBranch, mergedPr, provider);
533​
534 expect(
535 nextThreadChangeRequestSnapshot({
536 threadBranch: featureBranch,
537 gitStatus: null,
538 snapshot: terminalSnapshot,
539 retainTerminalOnBranchMismatch: true,
540 }),
541 ).toBeUndefined();
542 expect(
543 resolveDisplayedThreadPr({
544 threadBranch: featureBranch,
545 gitStatus: null,
546 snapshot: terminalSnapshot,
547 retainTerminalOnBranchMismatch: true,
548 }),
549 ).toEqual(mergedPr);
550 });
551​
552 it("shows the last matching PR snapshot while its live status lease is released", () => {
553 const openPr = { ...mergedPr, state: "open" as const };
554 const input = {
555 threadBranch: featureBranch,
556 gitStatus: null,
557 snapshot: snapshotFor(featureBranch, openPr, provider),
558 retainTerminalOnBranchMismatch: false,
559 };
560 expect(resolveDisplayedThreadPr(input)).toEqual(openPr);
561 expect(resolveDisplayedThreadPrProvider(input)).toEqual(provider);
562 expect(resolveDisplayedThreadPr({ ...input, threadBranch: "feature/other" })).toBeNull();
563 expect(
564 resolveDisplayedThreadPr({
565 ...input,
566 snapshot: { ...input.snapshot, linkedPullRequest },
567 }),
568 ).toBeNull();
569 });
570​
571 it("retains a merged PR after a main checkout", () => {
572 const matchingStatus = status({
573 refName: featureBranch,
574 pr: mergedPr,
575 sourceControlProvider: provider,
576 });
577 const cached = nextThreadChangeRequestSnapshot({
578 threadBranch: featureBranch,
579 gitStatus: matchingStatus,
580 snapshot: undefined,
581 retainTerminalOnBranchMismatch: true,
582 });
583 expect(cached).not.toBeNull();
584 expect(cached).not.toBeUndefined();
585​
586 const mainStatus = status({ refName: "main", pr: null, isDefaultRef: true });
587 const displayed = resolveDisplayedThreadPr({
588 threadBranch: "main",
589 gitStatus: mainStatus,
590 snapshot: cached as ThreadChangeRequestSnapshot,
591 retainTerminalOnBranchMismatch: true,
592 });
593 expect(displayed?.state).toBe("merged");
594 });
595​
596 it("refreshes a cached snapshot when a pull request becomes ready", () => {
597 const readyPr = { ...mergedPr, state: "open" as const };
598 const draftPr = { ...readyPr, isDraft: true };
599​
600 expect(
601 threadChangeRequestSnapshotsEqual(
602 snapshotFor(featureBranch, draftPr),
603 snapshotFor(featureBranch, readyPr),
604 ),
605 ).toBe(false);
606 });
607});
608​
609describe("threadChangeRequestSnapshotsAtom", () => {
610 it.effect("retains snapshots while sidebar and chat consumers are unmounted", () =>
611 Effect.gen(function* () {
612 const registry = AtomRegistry.make();
613 const threadKey = "environment-1:thread-1";
614 const snapshot = snapshotFor("feature/current", mergedFeaturePr());
615​
616 const unmount = registry.mount(threadChangeRequestSnapshotsAtom);
617 registry.set(threadChangeRequestSnapshotsAtom, new Map([[threadKey, snapshot]]));
618 unmount();
619​
620 yield* Effect.yieldNow;
621​
622 const remount = registry.mount(threadChangeRequestSnapshotsAtom);
623 expect(registry.get(threadChangeRequestSnapshotsAtom).get(threadKey)).toEqual(snapshot);
624​
625 remount();
626 registry.dispose();
627 }),
628 );
629});
630​
631describe("prStatusIndicator", () => {
632 it("formats PR tooltips with number, uppercase status, and title", () => {
633 expect(prStatusIndicator(status().pr, undefined)).toMatchObject({
634 tooltip: "PR #42 - Open: PR branch",
635 tooltipLead: "PR #42 - Open",
636 tooltipTitle: "PR branch",
637 });
638 });
639​
640 it("uses red for closed pull requests", () => {
641 const closedPr = status().pr;
642 if (!closedPr) throw new Error("Expected pull request fixture");
643​
644 expect(prStatusIndicator({ ...closedPr, state: "closed" }, undefined)?.colorClass).toContain(
645 "text-red-600",
646 );
647 });
648​
649 it("uses gray and draft wording for draft pull requests", () => {
650 const draftPr = status().pr;
651 if (!draftPr) throw new Error("Expected pull request fixture");
652​
653 expect(prStatusIndicator({ ...draftPr, isDraft: true }, undefined)).toMatchObject({
654 label: "PR draft",
655 colorClass: "text-zinc-500 dark:text-zinc-400/80",
656 tooltipLead: "PR #42 - Draft",
657 });
658 });
659});
660​
661describe("resolveThreadPullRequestBadgePresentation", () => {
662 const url = "https://github.com/pingdotgg/t3code/pull/42";
663​
664 it("returns the pending pull-request badge when no snapshot is available", () => {
665 expect(
666 resolveThreadPullRequestBadgePresentation({
667 badge: null,
668 number: 42,
669 url,
670 status: null,
671 }),
672 ).toEqual({
673 Icon: PullRequestGlyph.pullRequest,
674 toneClassName: "text-muted-foreground",
675 label: "PR #42, status pending",
676 text: 42,
677 });
678 });
679​
680 it.each([
681 [
682 "open",
683 { state: "open", isDraft: false },
684 PullRequestGlyph.pullRequest,
685 "text-emerald-600 dark:text-emerald-300/90",
686 "PR #42 - Open: PR branch",
687 ],
688 [
689 "draft",
690 { state: "open", isDraft: true },
691 PullRequestGlyph.draft,
692 "text-zinc-500 dark:text-zinc-400/80",
693 "PR #42 - Draft: PR branch",
694 ],
695 [
696 "closed",
697 { state: "closed", isDraft: false },
698 PullRequestGlyph.closed,
699 "text-red-600 dark:text-red-300/90",
700 "PR #42 - Closed: PR branch",
701 ],
702 [
703 "merged",
704 { state: "merged", isDraft: false },
705 PullRequestGlyph.merged,
706 "text-violet-600 dark:text-violet-300/90",
707 "PR #42 - Merged: PR branch",
708 ],
709 ] as const)(
710 "keeps the %s state for one linked pull request",
711 (_state, prOverrides, expectedIcon, expectedToneClassName, expectedLabel) => {
712 const fixture = status().pr;
713 if (!fixture) throw new Error("Expected pull request fixture");
714 const prStatus = prStatusIndicator({ ...fixture, ...prOverrides }, undefined);
715 if (!prStatus) throw new Error("Expected pull request status");
716​
717 expect(
718 resolveThreadPullRequestBadgePresentation({
719 badge: { kind: "pull-request", others: 0, state: "open" },
720 number: fixture.number,
721 url: fixture.url,
722 status: prStatus,
723 }),
724 ).toEqual({
725 Icon: expectedIcon,
726 toneClassName: expectedToneClassName,
727 label: expectedLabel,
728 text: fixture.number,
729 });
730 },
731 );
732​
733 it.each([
734 ["open", "text-emerald-600 dark:text-emerald-300/90"],
735 ["draft", "text-zinc-500 dark:text-zinc-400/80"],
736 ["merged", "text-violet-600 dark:text-violet-300/90"],
737 ] as const)(
738 "uses a layers badge with the %s stack tone without a link identity",
739 (state, expectedToneClassName) => {
740 expect(
741 resolveThreadPullRequestBadgePresentation({
742 badge: { kind: "stack", layers: 3, state },
743 status: null,
744 }),
745 ).toEqual({
746 Icon: PullRequestGlyph.stack,
747 toneClassName: expectedToneClassName,
748 label: `Stack of 3 pull requests, ${state}`,
749 text: 3,
750 });
751 },
752 );
753​
754 it.each([
755 ["open", PullRequestGlyph.pullRequest, "text-emerald-600 dark:text-emerald-300/90"],
756 ["draft", PullRequestGlyph.draft, "text-zinc-500 dark:text-zinc-400/80"],
757 ["merged", PullRequestGlyph.merged, "text-violet-600 dark:text-violet-300/90"],
758 ] as const)(
759 "draws the count of unrelated linked pull requests with their %s aggregate state",
760 (state, expectedIcon, expectedToneClassName) => {
761 const fixture = status().pr;
762 if (!fixture) throw new Error("Expected pull request fixture");
763 const closedStatus = prStatusIndicator(
764 { ...fixture, state: "closed", isDraft: false },
765 undefined,
766 );
767 if (!closedStatus) throw new Error("Expected pull request status");
768​
769 expect(
770 resolveThreadPullRequestBadgePresentation({
771 badge: { kind: "pull-request", others: 2, state },
772 number: fixture.number,
773 url: fixture.url,
774 status: closedStatus,
775 }),
776 ).toEqual({
777 Icon: expectedIcon,
778 toneClassName: expectedToneClassName,
779 label: `PR #42 - Closed: PR branch, and 2 more linked; overall ${state}`,
780 text: "+3",
781 });
782 },
783 );
784​
785 it("omits the control when neither a stack nor a linked identity can be shown", () => {
786 expect(resolveThreadPullRequestBadgePresentation({ badge: null, status: null })).toBeNull();
787 });
788});