Open History to see the last commit
1import type { ThreadPullRequestLink } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { linkedPullRequestSnapshotStatus } from "./ThreadStatusIndicators";
5
6describe("linked pull request snapshots", () => {
7 const link: ThreadPullRequestLink = {
8 host: "gitlab.example.com",
9 repository: "acme/web",
10 number: 42,
11 url: "https://gitlab.example.com/acme/web/-/merge_requests/42",
12 source: "manual",
13 linkedAt: "2026-01-01T00:00:00Z",
14 stack: null,
15 snapshot: null,
16 };
17 it("keeps unsynced links unknown", () => {
18 expect(linkedPullRequestSnapshotStatus(link)).toBeNull();
19 });
20 it("uses the snapshot state and branches with the linked identity", () => {
21 const result = linkedPullRequestSnapshotStatus({
22 ...link,
23 snapshot: {
24 state: "merged",
25 title: "Change",
26 headBranch: "feature",
27 baseBranch: "main",
28 isDraft: false,
29 updatedAt: "2026-01-02T00:00:00Z",
30 syncedAt: "2026-01-03T00:00:00Z",
31 },
32 });
33 expect(result).toEqual({
34 pr: {
35 number: 42,
36 url: link.url,
37 title: "Change",
38 state: "merged",
39 isDraft: false,
40 headRef: "feature",
41 baseRef: "main",
42 updatedAt: "2026-01-02T00:00:00Z",
43 },
44 sourceControlProvider: { kind: "gitlab", name: "gitlab", baseUrl: "" },
45 });
46 });
47 it.each([
48 ["https://git.cafe/owner/repo/pulls/42", "gitcafe"],
49 ["https://staging.git.cafe/owner/repo/pulls/42", "gitcafe"],
50 ["https://codeberg.org/owner/repo/pulls/42", "forgejo"],
51 ["https://gitlab.example.com/acme/web/-/merge_requests/42", "gitlab"],
52 ["https://github.com/owner/repo/pull/42", "github"],
53 ])("classifies %s as %s", (url, kind) => {
54 const result = linkedPullRequestSnapshotStatus({
55 ...link,
56 url,
57 snapshot: {
58 state: "open",
59 title: "Change",
60 headBranch: "feature",
61 baseBranch: "main",
62 isDraft: false,
63 updatedAt: null,
64 syncedAt: "2026-01-03T00:00:00Z",
65 },
66 });
67 expect(result?.sourceControlProvider.kind).toBe(kind);
68 });
69});