Open History to see the last commit
1import type { PullRequestActivity, PullRequestCheck, PullRequestComment } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import {
4 normalizedReviewState,
5 pullRequestChecksSummary,
6 pullRequestReviewSummary,
7} from "./pullRequestStatus";
8
9const author = { login: "julius", name: null, avatarUrl: null };
10function review(state: string, at: string): PullRequestComment {
11 return {
12 id: `${state}:${at}`,
13 kind: "review",
14 author,
15 body: "",
16 createdAt: at,
17 url: null,
18 path: null,
19 reviewState: state,
20 };
21}
22function activity(
23 comments: readonly PullRequestComment[],
24): Pick<PullRequestActivity, "comments" | "commits"> {
25 return { comments, commits: [] };
26}
27function check(status: PullRequestCheck["status"]): PullRequestCheck {
28 return { name: status, status, url: null, description: null };
29}
30
31describe("mobile overview review status", () => {
32 it("uses each reviewer's latest verdict even when history arrives out of order", () => {
33 const result = pullRequestReviewSummary(
34 { reviewers: [] },
35 activity([
36 review("CHANGES_REQUESTED", "2026-10-10T10:00:00Z"),
37 review("APPROVED", "2026-10-10T09:00:00Z"),
38 ]),
39 );
40 expect(result.title).toBe("Changes requested");
41 expect(result.reviews).toHaveLength(1);
42 });
43
44 it("does not claim a dismissed approval or an approval preceding the latest commit", () => {
45 const approved = review("APPROVED", "2026-10-10T09:00:00Z");
46 expect(
47 pullRequestReviewSummary(
48 { reviewers: [] },
49 activity([approved, review("DISMISSED", "2026-10-10T10:00:00Z")]),
50 ).reviews,
51 ).toEqual([]);
52 const result = pullRequestReviewSummary(
53 { reviewers: [author] },
54 {
55 comments: [approved],
56 commits: [
57 { oid: "abc123", messageHeadline: "Update", committedDate: "2026-10-10T10:00:00Z" },
58 ],
59 },
60 );
61 expect(result.title).toBe("Awaiting review");
62 expect(result.reviews.map((review) => review.outdated)).toEqual([true]);
63 });
64
65 it("keeps an approval when a later review only comments, and normalizes provider spelling", () => {
66 const result = pullRequestReviewSummary(
67 { reviewers: [] },
68 activity([
69 review("approved", "2026-10-10T09:00:00Z"),
70 review("COMMENTED", "2026-10-10T10:00:00Z"),
71 ]),
72 );
73 expect(result.title).toBe("Approved by julius");
74 expect(result.reviews).toHaveLength(1);
75 expect(
76 pullRequestReviewSummary(
77 { reviewers: [] },
78 activity([review("changes-requested", "2026-10-10T11:00:00Z")]),
79 ).title,
80 ).toBe("Changes requested");
81 });
82});
83
84describe("mobile review state spelling", () => {
85 it("reads GitHub's uppercase and Bitbucket's or GitCafe's lowercase verdicts alike", () => {
86 expect(normalizedReviewState("APPROVED")).toBe("APPROVED");
87 expect(normalizedReviewState("approved")).toBe("APPROVED");
88 expect(normalizedReviewState("CHANGES_REQUESTED")).toBe("CHANGES_REQUESTED");
89 expect(normalizedReviewState("changes_requested")).toBe("CHANGES_REQUESTED");
90 expect(normalizedReviewState("changes-requested")).toBe("CHANGES_REQUESTED");
91 expect(normalizedReviewState("commented")).toBe("COMMENTED");
92 expect(normalizedReviewState(null)).toBeUndefined();
93 });
94});
95
96describe("mobile overview check status", () => {
97 it("prioritizes failed checks while others are running", () => {
98 expect(
99 pullRequestChecksSummary({ checks: [check("success"), check("pending"), check("failure")] }),
100 ).toMatchObject({ title: "1 check failing", count: "1 of 3" });
101 expect(
102 pullRequestChecksSummary({ checks: [check("success"), check("cancelled")] }),
103 ).toMatchObject({ title: "1 check failing", tint: "accent-danger-foreground" });
104 });
105});