Skip to content

Commit 92d0ad3

Browse files
authored
test(RadarChart): add responsive breakpoints and geometry proof tests (JhaSourav07#2235)
## Description Fixes JhaSourav07#1519 #### Changes Made: - Added 4 focused tests - Reopened PR ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [X] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview No visual changes ## Checklist before requesting a review: - [X] I have read the `CONTRIBUTING.md` file. - [X] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [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 started the repo. - [X] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [X] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents a79a52c + dae2980 commit 92d0ad3

1 file changed

Lines changed: 68 additions & 3 deletions

File tree

components/dashboard/RadarChart.test.tsx

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { render, screen } from '@testing-library/react';
33
import { describe, expect, it, vi } from 'vitest';
44
import RadarChart from './RadarChart';
5+
import '@testing-library/jest-dom/vitest';
56

67
vi.mock('framer-motion', () => ({
78
motion: {
@@ -48,9 +49,9 @@ describe('RadarChart', () => {
4849
<RadarChart languagesA={mockLangsA} languagesB={mockLangsB} labelA="User A" labelB="User B" />
4950
);
5051

51-
expect(screen.getByText('Language Dominance')).toBeDefined();
52-
expect(screen.getByText('User A')).toBeDefined();
53-
expect(screen.getByText('User B')).toBeDefined();
52+
expect(screen.getByText('Language Dominance')).toBeInTheDocument();
53+
expect(screen.getByText('User A')).toBeInTheDocument();
54+
expect(screen.getByText('User B')).toBeInTheDocument();
5455

5556
expect(screen.getAllByText('TypeScript')).toBeDefined();
5657
expect(screen.getAllByText('Python')).toBeDefined();
@@ -123,4 +124,68 @@ describe('RadarChart', () => {
123124
const circles = container.querySelectorAll('circle');
124125
expect(circles.length).toBeGreaterThan(0);
125126
});
127+
128+
it('check generation of different polygon coordinates for different score magnitudes', () => {
129+
const highScores = [
130+
{ name: 'TypeScript', percentage: 100, color: '#3178c6' },
131+
{ name: 'Python', percentage: 100, color: '#3572A5' },
132+
{ name: 'JavaScript', percentage: 100, color: '#f1e05a' },
133+
];
134+
const lowScores = [
135+
{ name: 'TypeScript', percentage: 10, color: '#3178c6' },
136+
{ name: 'Python', percentage: 10, color: '#3572A5' },
137+
{ name: 'JavaScript', percentage: 10, color: '#f1e05a' },
138+
];
139+
140+
const { container } = render(
141+
<RadarChart languagesA={highScores} languagesB={lowScores} labelA="High" labelB="Low" />
142+
);
143+
144+
// 4 grid rings + 2 data polygons
145+
const polygons = container.querySelectorAll('polygon');
146+
expect(polygons.length).toBeGreaterThanOrEqual(6);
147+
148+
const CX = 160,
149+
CY = 160;
150+
const distanceOf = (c: Element) =>
151+
Math.hypot(
152+
parseFloat(c.getAttribute('cx') ?? '0') - CX,
153+
parseFloat(c.getAttribute('cy') ?? '0') - CY
154+
);
155+
156+
const circles = Array.from(container.querySelectorAll('circle'));
157+
expect(circles).toHaveLength(6); // all pct > 0, 3 per user
158+
159+
const avgHigh = circles.slice(0, 3).reduce((s, c) => s + distanceOf(c), 0) / 3;
160+
const avgLow = circles.slice(3, 6).reduce((s, c) => s + distanceOf(c), 0) / 3;
161+
162+
expect(avgHigh).toBeGreaterThan(avgLow);
163+
});
164+
165+
describe('responsive rendering', () => {
166+
it.each([320, 768, 1280])(
167+
'checks rendering of chart structure at viewport width %i',
168+
(width) => {
169+
Object.defineProperty(window, 'innerWidth', {
170+
writable: true,
171+
configurable: true,
172+
value: width,
173+
});
174+
175+
const { container, unmount } = render(
176+
<RadarChart
177+
languagesA={mockLangsA}
178+
languagesB={mockLangsB}
179+
labelA="User A"
180+
labelB="User B"
181+
/>
182+
);
183+
184+
expect(container.querySelector('svg')).toBeInTheDocument();
185+
expect(screen.getByText('Language Dominance')).toBeInTheDocument();
186+
187+
unmount();
188+
}
189+
);
190+
});
126191
});

0 commit comments

Comments
 (0)