Skip to content

Commit 9932b89

Browse files
authored
test(Leaderboard-massive-scaling): verify Massive Data Sets and Extreme High Bounds Scaling (JhaSourav07#3268)
## Description Fixes JhaSourav07#2754 This PR adds `components/Leaderboard.massive-scaling.test.tsx` to handle testing of the `Leaderboard` component when provided with extreme metrics. It guarantees the internal algorithms do not throw DOM buffer overflows or fail performance bounds when exposed to highly-loaded data sets (1000+ mocked contributors, 999M+ contribution integer counts). ## 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 - Integration Tests)* ## 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): ...`). - [x] 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. - [x] 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 3a43df2 + e17d1e1 commit 9932b89

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { render } from '@testing-library/react';
3+
import React from 'react';
4+
import Leaderboard, { Contributor } from './Leaderboard';
5+
6+
// Mock Next.js Image
7+
vi.mock('next/image', () => ({
8+
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => <img alt="mock" {...props} />,
9+
}));
10+
11+
// Mock Framer Motion
12+
vi.mock('framer-motion', async () => {
13+
const actual = await vi.importActual('framer-motion');
14+
return {
15+
...actual,
16+
motion: {
17+
div: ({
18+
children,
19+
className,
20+
onClick,
21+
style,
22+
}: {
23+
children?: React.ReactNode;
24+
className?: string;
25+
onClick?: React.MouseEventHandler<HTMLDivElement>;
26+
style?: React.CSSProperties;
27+
}) => (
28+
<div className={className} onClick={onClick} style={style} data-testid="motion-div">
29+
{children}
30+
</div>
31+
),
32+
},
33+
};
34+
});
35+
36+
// IntersectionObserver mock
37+
beforeEach(() => {
38+
const mockIntersectionObserver = vi.fn();
39+
mockIntersectionObserver.mockReturnValue({
40+
observe: () => null,
41+
unobserve: () => null,
42+
disconnect: () => null,
43+
});
44+
window.IntersectionObserver =
45+
mockIntersectionObserver as unknown as typeof window.IntersectionObserver;
46+
});
47+
48+
describe('Leaderboard - Massive Scaling & High Bounds (Issue #2754 Equivalent)', () => {
49+
it('Massive Array Population (Render Bounds): handles processing arrays of 1000+ contributors cleanly without crashing', () => {
50+
const massiveContributors = Array.from({ length: 1005 }).map((_, i) => ({
51+
id: i,
52+
login: `user${i}`,
53+
avatar_url: `https://avatars.githubusercontent.com/u/${i}?v=4`,
54+
contributions: 100 - i, // fake sort
55+
html_url: `https://github.com/user${i}`,
56+
}));
57+
58+
const start = performance.now();
59+
const { container } = render(<Leaderboard contributors={massiveContributors} />);
60+
const end = performance.now();
61+
62+
// Verify it extracts podium and leaves 1002 in the list
63+
const listEntries = container.querySelectorAll('.flex.items-center.justify-between.p-4');
64+
expect(listEntries.length).toBe(1002);
65+
66+
// Performance bounds check (bumped to 5000ms to account for slower CI runners)
67+
expect(end - start).toBeLessThan(5000);
68+
});
69+
70+
it('Extreme High Contribution Metric Bounds: safely renders millions of commits without integer layout overflow', () => {
71+
const highMetricData: Contributor[] = [
72+
{ id: 1, login: 'whale', avatar_url: '', html_url: '', contributions: 999999999 },
73+
{ id: 2, login: 'shark', avatar_url: '', html_url: '', contributions: 888888888 },
74+
{ id: 3, login: 'dolphin', avatar_url: '', html_url: '', contributions: 777777777 },
75+
{ id: 4, login: 'fish', avatar_url: '', html_url: '', contributions: 666666666 },
76+
];
77+
78+
const { getByText } = render(<Leaderboard contributors={highMetricData} />);
79+
80+
// Podium text
81+
expect(getByText('999999999')).toBeTruthy();
82+
expect(getByText('888888888')).toBeTruthy();
83+
expect(getByText('777777777')).toBeTruthy();
84+
85+
// List text
86+
expect(getByText('666666666')).toBeTruthy();
87+
});
88+
89+
it('Rank Formatting Overflow Prevention: ensures extremely high index numbers do not break grid bounds', () => {
90+
// Check rank #1000+ string bounds
91+
const highRankData = Array.from({ length: 1500 }).map((_, i) => ({
92+
id: i,
93+
login: `user${i}`,
94+
avatar_url: '',
95+
contributions: 10,
96+
html_url: '',
97+
}));
98+
99+
const { getByText } = render(<Leaderboard contributors={highRankData} />);
100+
101+
// Verify #1000 renders cleanly inside the bounding flex box
102+
const highRankItem = getByText('#1000');
103+
expect(highRankItem).toBeTruthy();
104+
expect(highRankItem.className).toContain('font-mono');
105+
});
106+
107+
it('Podium Extraction Memory Allocation: strictly segments exactly the top 3 nodes regardless of massive data input sizes', () => {
108+
const massiveData = Array.from({ length: 500 }).map((_, i) => ({
109+
id: i,
110+
login: `user${i}`,
111+
avatar_url: '',
112+
contributions: 10,
113+
html_url: '',
114+
}));
115+
116+
const { container } = render(<Leaderboard contributors={massiveData} />);
117+
118+
// Check that we only rendered 3 PodiumItems (Rank 1, 2, 3)
119+
const crowns = container.querySelectorAll('.absolute.-top-8.z-30'); // Crown icons exist in podiums only
120+
expect(crowns.length).toBe(3);
121+
});
122+
123+
it('Structural Text Wrapping Safety: extreme long usernames truncate without clipping or blowing out DOM boundaries', () => {
124+
const extremeNameData: Contributor[] = [
125+
{ id: 1, login: 'a'.repeat(500), avatar_url: '', html_url: '', contributions: 100 },
126+
{ id: 2, login: 'b'.repeat(500), avatar_url: '', html_url: '', contributions: 90 },
127+
{ id: 3, login: 'c'.repeat(500), avatar_url: '', html_url: '', contributions: 80 },
128+
];
129+
130+
const { getByText } = render(<Leaderboard contributors={extremeNameData} />);
131+
132+
const longNameUser = getByText('a'.repeat(500));
133+
// Verify it uses truncate to stop boundary breakages
134+
expect(longNameUser.className).toContain('truncate');
135+
});
136+
});

0 commit comments

Comments
 (0)