Skip to content

Commit cdd5fe5

Browse files
test(ui): verify responsive rendering and elements of RadarChart (JhaSourav07#1529)
1 parent fd2a3be commit cdd5fe5

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

components/dashboard/RadarChart.test.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,88 @@ describe('RadarChart', () => {
7878
expect(screen.getAllByText('JavaScript')).toBeDefined();
7979
expect(screen.getAllByText('Python')).toBeDefined();
8080
});
81+
82+
it('renders chart elements and layout structure visible across viewport sizes', () => {
83+
const mockLangsA = [
84+
{ name: 'TypeScript', percentage: 80, color: '#3178c6' },
85+
{ name: 'Python', percentage: 60, color: '#3572A5' },
86+
{ name: 'JavaScript', percentage: 40, color: '#f1e05a' },
87+
];
88+
89+
const mockLangsB = [
90+
{ name: 'TypeScript', percentage: 50, color: '#3178c6' },
91+
{ name: 'Python', percentage: 70, color: '#3572A5' },
92+
{ name: 'JavaScript', percentage: 30, color: '#f1e05a' },
93+
];
94+
95+
const { container } = render(
96+
<RadarChart languagesA={mockLangsA} languagesB={mockLangsB} labelA="User A" labelB="User B" />
97+
);
98+
99+
// Check that SVG element is rendered
100+
const svg = container.querySelector('svg');
101+
expect(svg).toBeDefined();
102+
103+
// Check that grid polygons are rendered (concentric levels)
104+
const polygons = container.querySelectorAll('polygon');
105+
expect(polygons.length).toBeGreaterThan(0);
106+
107+
// Check that axis lines are rendered
108+
const lines = container.querySelectorAll('line');
109+
expect(lines.length).toBeGreaterThan(0);
110+
111+
// Check that axis labels are rendered
112+
expect(screen.getAllByText('TypeScript')).toBeDefined();
113+
expect(screen.getAllByText('Python')).toBeDefined();
114+
expect(screen.getAllByText('JavaScript')).toBeDefined();
115+
116+
// Check that data points (circles) are rendered
117+
const circles = container.querySelectorAll('circle');
118+
expect(circles.length).toBeGreaterThan(0);
119+
});
120+
121+
it('dynamically scales axis points based on dataset max score', () => {
122+
// Mock dataset with specific maximum score
123+
const mockLangsA = [
124+
{ name: 'TypeScript', percentage: 100, color: '#3178c6' }, // Max score
125+
{ name: 'Python', percentage: 75, color: '#3572A5' },
126+
{ name: 'JavaScript', percentage: 50, color: '#f1e05a' },
127+
];
128+
129+
const mockLangsB = [
130+
{ name: 'TypeScript', percentage: 90, color: '#3178c6' },
131+
{ name: 'Python', percentage: 60, color: '#3572A5' },
132+
{ name: 'JavaScript', percentage: 30, color: '#f1e05a' },
133+
];
134+
135+
const { container } = render(
136+
<RadarChart languagesA={mockLangsA} languagesB={mockLangsB} labelA="User A" labelB="User B" />
137+
);
138+
139+
// Verify that polygons are rendered with points attribute
140+
const polygons = container.querySelectorAll('polygon');
141+
expect(polygons.length).toBeGreaterThan(0);
142+
143+
// Check that the data polygons have points attribute (indicating scaling)
144+
const dataPolygons = Array.from(polygons).filter((p) =>
145+
p.getAttribute('points')?.includes(',')
146+
);
147+
expect(dataPolygons.length).toBeGreaterThan(0);
148+
149+
// Verify that circles (data points) are rendered at different positions
150+
const circles = container.querySelectorAll('circle');
151+
expect(circles.length).toBeGreaterThan(0);
152+
153+
// Get all circle positions to verify they're scaled differently
154+
const circlePositions = Array.from(circles).map((circle) => ({
155+
cx: circle.getAttribute('cx'),
156+
cy: circle.getAttribute('cy'),
157+
}));
158+
159+
// Verify that not all circles are at the same position (indicating dynamic scaling)
160+
const uniquePositions = new Set(
161+
circlePositions.map((pos) => `${pos.cx},${pos.cy}`)
162+
);
163+
expect(uniquePositions.size).toBeGreaterThan(1);
164+
});
81165
});

0 commit comments

Comments
 (0)