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

threadPullRequestListLines.test.ts

74 lines2.1 KB

1import type { ThreadPullRequestLink } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { pullRequestListLines, resolveThreadPullRequestChains } from "./threadPullRequests.ts";
5​
6function link(
7 number: number,
8 head: string,
9 base: string,
10 updatedAt: string,
11 stack: ThreadPullRequestLink["stack"] = null,
12): ThreadPullRequestLink {
13 return {
14 host: "github.com",
15 repository: "acme/web",
16 number,
17 url: `https://github.com/acme/web/pull/${number}`,
18 source: "manual",
19 linkedAt: "2026-01-01T00:00:00.000Z",
20 snapshot: {
21 state: "open",
22 title: `PR ${number}`,
23 headBranch: head,
24 baseBranch: base,
25 isDraft: false,
26 updatedAt,
27 syncedAt: updatedAt,
28 },
29 stack,
30 };
32​
33describe("pullRequestListLines", () => {
34 it("orders newest first and keeps a stack together under its base layer", () => {
35 const lines = pullRequestListLines(
36 resolveThreadPullRequestChains([
37 link(1, "a", "main", "2026-01-01T10:00:00Z"),
38 link(2, "b", "a", "2026-01-01T12:00:00Z"),
39 link(9, "solo", "main", "2026-01-01T11:00:00Z"),
40 link(5, "old", "main", "2026-01-01T09:00:00Z"),
41 ]),
42 );
43 expect(lines.map((line) => [line.link.number, line.depth, line.stack?.size ?? null])).toEqual([
44 [1, 0, 2],
45 [2, 1, null],
46 [9, 0, null],
47 [5, 0, null],
48 ]);
49 });
50​
51 it("marks native stacks on their base layer", () => {
52 const stack = {
53 kind: "native" as const,
54 id: "1",
55 number: 1,
56 url: "https://github.com/acme/web/stacks/1",
57 base: "main",
58 layers: [
59 { number: 3, headBranch: "x", state: "open" as const },
60 { number: 4, headBranch: "y", state: "open" as const },
61 ],
62 };
63 const lines = pullRequestListLines(
64 resolveThreadPullRequestChains([
65 link(4, "y", "x", "2026-01-01T10:00:00Z", stack),
66 link(3, "x", "main", "2026-01-01T10:00:00Z", stack),
67 ]),
68 );
69 expect(lines.map((line) => [line.link.number, line.depth, line.stack?.kind ?? null])).toEqual([
70 [3, 0, "native"],
71 [4, 1, null],
72 ]);
73 });
74});