Skip to content

Commit a23b22b

Browse files
test(Leaderboard): verify Massive Data Sets and Extreme High Bounds Scaling
1 parent e3369ea commit a23b22b

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)