Skip to content

Commit 2075a0b

Browse files
authored
test(contributors): add accessibility coverage (JhaSourav07#3078)
## Description Fixes JhaSourav07#2856 Added accessibility-focused unit tests for `app/contributors/page.tsx` to validate rendering behavior, client component integration, and fallback handling. ### Changes - Added `app/contributors/page.accessibility.test.tsx` - Mocked `ContributorsClient` to isolate page-level behavior - Verified the contributors client component renders successfully - Tested contributor data propagation from the server page to the client layer - Verified `totalContributions` is calculated and passed correctly - Verified `topContributors` data is passed to the client component - Tested fallback behavior when contributor fetching fails and returns an empty dataset - Improved coverage around accessibility-related rendering stability and component integration ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only changes) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no SVG changes made). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 5b030e4 + 44bc93f commit 2075a0b

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// app/contributors/page.accessibility.test.tsx
2+
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
4+
import { render, screen } from '@testing-library/react';
5+
import '@testing-library/jest-dom';
6+
7+
type ContributorsClientProps = {
8+
contributors: unknown[];
9+
totalContributions: number;
10+
topContributors: unknown[];
11+
};
12+
13+
const mockContributorsClient = vi.fn((_props?: ContributorsClientProps) => (
14+
<div data-testid="contributors-client">Contributors Client</div>
15+
));
16+
17+
vi.mock('./ContributorsClient', () => ({
18+
default: (props: ContributorsClientProps) => mockContributorsClient(props),
19+
}));
20+
21+
describe('ContributorsPage Accessibility', () => {
22+
beforeEach(() => {
23+
vi.clearAllMocks();
24+
});
25+
26+
it('renders the contributors client container', async () => {
27+
const { default: ContributorsPage } = await import('./page');
28+
29+
const page = await ContributorsPage();
30+
31+
render(page);
32+
33+
expect(screen.getByTestId('contributors-client')).toBeInTheDocument();
34+
});
35+
36+
it('passes contributors array to accessible client layer', async () => {
37+
const { default: ContributorsPage } = await import('./page');
38+
39+
const page = await ContributorsPage();
40+
41+
render(page);
42+
43+
expect(mockContributorsClient).toHaveBeenCalled();
44+
45+
const props = mockContributorsClient.mock.calls[0][0] as ContributorsClientProps;
46+
47+
expect(Array.isArray(props.contributors)).toBe(true);
48+
});
49+
50+
it('passes totalContributions to client component', async () => {
51+
const { default: ContributorsPage } = await import('./page');
52+
53+
const page = await ContributorsPage();
54+
55+
render(page);
56+
57+
const props = mockContributorsClient.mock.calls[0][0] as ContributorsClientProps;
58+
59+
expect(typeof props.totalContributions).toBe('number');
60+
});
61+
62+
it('passes topContributors collection to client component', async () => {
63+
const { default: ContributorsPage } = await import('./page');
64+
65+
const page = await ContributorsPage();
66+
67+
render(page);
68+
69+
const props = mockContributorsClient.mock.calls[0][0] as ContributorsClientProps;
70+
71+
expect(Array.isArray(props.topContributors)).toBe(true);
72+
});
73+
74+
it('renders successfully when contributor data is empty', async () => {
75+
const originalFetch = global.fetch;
76+
77+
global.fetch = vi.fn().mockResolvedValue({
78+
ok: false,
79+
status: 500,
80+
headers: {
81+
get: () => null,
82+
},
83+
} as unknown as Response);
84+
85+
const { default: ContributorsPage } = await import('./page');
86+
87+
const page = await ContributorsPage();
88+
89+
render(page);
90+
91+
expect(screen.getByTestId('contributors-client')).toBeInTheDocument();
92+
93+
global.fetch = originalFetch;
94+
});
95+
});

0 commit comments

Comments
 (0)