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

ThreadStatusIndicators.test.ts

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