Skip to content

Commit ff9d4cc

Browse files
committed
test: adds RepoGitHubLink tests and formatDuration NaN guard
1 parent 5592758 commit ff9d4cc

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/app/lib/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function formatDuration(startedAt: string, completedAt: string | null): s
6464
if (!startedAt) return "--";
6565
if (!completedAt) return "--";
6666
const diffMs = Date.parse(completedAt) - Date.parse(startedAt);
67-
if (diffMs <= 0) return "--";
67+
if (isNaN(diffMs) || diffMs <= 0) return "--";
6868
const totalSec = Math.floor(diffMs / 1000);
6969
const h = Math.floor(totalSec / 3600);
7070
const m = Math.floor((totalSec % 3600) / 60);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render } from "@solidjs/testing-library";
3+
import RepoGitHubLink from "../../src/app/components/shared/RepoGitHubLink";
4+
5+
describe("RepoGitHubLink", () => {
6+
it("renders issues link with correct href and label", () => {
7+
const { container } = render(() => (
8+
<RepoGitHubLink repoFullName="owner/repo" section="issues" />
9+
));
10+
const link = container.querySelector("a")!;
11+
expect(link.getAttribute("href")).toBe("https://github.com/owner/repo/issues");
12+
expect(link.getAttribute("aria-label")).toBe("Open owner/repo issues on GitHub");
13+
expect(link.getAttribute("target")).toBe("_blank");
14+
expect(link.getAttribute("rel")).toBe("noopener noreferrer");
15+
});
16+
17+
it("renders pulls link with correct href and label", () => {
18+
const { container } = render(() => (
19+
<RepoGitHubLink repoFullName="owner/repo" section="pulls" />
20+
));
21+
const link = container.querySelector("a")!;
22+
expect(link.getAttribute("href")).toBe("https://github.com/owner/repo/pulls");
23+
expect(link.getAttribute("aria-label")).toBe("Open owner/repo pull requests on GitHub");
24+
});
25+
26+
it("renders actions link with correct href and label", () => {
27+
const { container } = render(() => (
28+
<RepoGitHubLink repoFullName="owner/repo" section="actions" />
29+
));
30+
const link = container.querySelector("a")!;
31+
expect(link.getAttribute("href")).toBe("https://github.com/owner/repo/actions");
32+
expect(link.getAttribute("aria-label")).toBe("Open owner/repo actions on GitHub");
33+
});
34+
35+
it("renders ExternalLinkIcon SVG with aria-hidden", () => {
36+
const { container } = render(() => (
37+
<RepoGitHubLink repoFullName="owner/repo" section="issues" />
38+
));
39+
const svg = container.querySelector("svg");
40+
expect(svg).not.toBeNull();
41+
expect(svg!.getAttribute("aria-hidden")).toBe("true");
42+
});
43+
});

tests/lib/format.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ describe("formatDuration", () => {
226226
it("returns '<1s' for sub-second duration", () => {
227227
expect(formatDuration("2026-03-21T10:00:00.000Z", "2026-03-21T10:00:00.500Z")).toBe("<1s");
228228
});
229+
230+
it("returns '--' for invalid date strings", () => {
231+
expect(formatDuration("not-a-date", "2026-03-21T10:00:00Z")).toBe("--");
232+
expect(formatDuration("2026-03-21T10:00:00Z", "not-a-date")).toBe("--");
233+
});
229234
});
230235

231236
describe("prSizeCategory", () => {

tests/stores/view.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ describe("ViewStateSchema", () => {
190190
expect(result.sortPreferences).toEqual({});
191191
expect(result.ignoredItems).toEqual([]);
192192
expect(result.globalFilter).toEqual({ org: null, repo: null });
193+
expect(result.hideDepDashboard).toBe(true);
193194
});
194195

195196
it("handles missing fields with defaults", () => {

0 commit comments

Comments
 (0)