-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContributionCard.test.tsx
More file actions
87 lines (71 loc) · 2.62 KB
/
Copy pathContributionCard.test.tsx
File metadata and controls
87 lines (71 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { describe, it, expect, vi, afterEach } from "vitest";
import { render, screen, cleanup } from "@testing-library/react";
import { ContributionCard } from "@/components/ContributionCard";
import type { ContributionDetail } from "@/lib/types";
// Mock ExpandedPRDetail and ExpandedIssueDetail
vi.mock("@/components/ExpandedPRDetail", () => ({
ExpandedPRDetail: ({ number }: { number: number }) => (
<div data-testid="pr-detail">PR Detail #{number}</div>
),
}));
vi.mock("@/components/ExpandedReviewDetail", () => ({
ExpandedReviewDetail: ({ number }: { number: number }) => (
<div data-testid="review-detail">Review Detail #{number}</div>
),
}));
vi.mock("@/components/ExpandedIssueDetail", () => ({
ExpandedIssueDetail: ({ number }: { number: number }) => (
<div data-testid="issue-detail">Issue Detail #{number}</div>
),
}));
afterEach(cleanup);
const prItem: ContributionDetail = {
id: 1,
number: 42,
title: "Fix consensus bug",
repoNameWithOwner: "bitcoin/bitcoin",
type: "pr",
state: "merged",
createdAt: "2024-06-01T00:00:00Z",
closedAt: "2024-06-02T00:00:00Z",
url: "https://github.com/bitcoin/bitcoin/pull/42",
};
const issueItem: ContributionDetail = {
id: 2,
number: 10,
title: "Tracking issue",
repoNameWithOwner: "bitcoin/bitcoin",
type: "issue",
state: "open",
createdAt: "2024-07-01T00:00:00Z",
closedAt: null,
url: "https://github.com/bitcoin/bitcoin/issues/10",
};
describe("ContributionCard", () => {
it("renders PR card with title and repo", () => {
render(<ContributionCard item={prItem} />);
expect(screen.getByText("Fix consensus bug")).toBeInTheDocument();
expect(screen.getByText("bitcoin/bitcoin")).toBeInTheDocument();
expect(screen.getByText("merged")).toBeInTheDocument();
});
it("renders issue card", () => {
render(<ContributionCard item={issueItem} />);
expect(screen.getByText("Tracking issue")).toBeInTheDocument();
expect(screen.getByText("open")).toBeInTheDocument();
});
it("has external link to GitHub", () => {
render(<ContributionCard item={prItem} />);
const link = screen.getByLabelText("Open #42 on GitHub");
expect(link).toHaveAttribute("href", "https://github.com/bitcoin/bitcoin/pull/42");
expect(link).toHaveAttribute("target", "_blank");
});
it("PR card has expand button role", () => {
render(<ContributionCard item={prItem} />);
const expandable = screen.getByRole("button");
expect(expandable).toBeInTheDocument();
});
it("issue card has expand button", () => {
render(<ContributionCard item={issueItem} />);
expect(screen.getByRole("button")).toBeInTheDocument();
});
});