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

pullRequestPresentation.test.ts

28 lines1.1 KB

1import type { PullRequestCheck } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { pullRequestChecksCountLabel } from "./pullRequestPresentation";
5​
6const checks = (...statuses: ReadonlyArray<PullRequestCheck["status"]>): PullRequestCheck[] =>
7 statuses.map((status) => ({ name: "ci", status, description: null, url: null }));
8​
9describe("pullRequestChecksCountLabel", () => {
10 it("names the most urgent group: failed, then awaiting action, then running", () => {
11 expect(
12 pullRequestChecksCountLabel(
13 checks("failure", "cancelled", "action-required", "pending", "success"),
14 ),
15 ).toBe("2 failed");
16 expect(pullRequestChecksCountLabel(checks("action-required", "pending", "pending"))).toBe(
17 "1 awaiting action",
18 );
19 expect(pullRequestChecksCountLabel(checks("pending", "pending", "success", "skipped"))).toBe(
20 "2 running",
21 );
22 });
23​
24 it("shows nothing once no check is failed, waiting or running", () => {
25 expect(pullRequestChecksCountLabel(checks("success", "skipped", "neutral"))).toBeNull();
26 expect(pullRequestChecksCountLabel([])).toBeNull();
27 });
28});