From 40f9048549c777e3b12fa213f7339617f118c658 Mon Sep 17 00:00:00 2001 From: Thacker-Meet Date: Fri, 12 Jun 2026 17:14:31 +0530 Subject: [PATCH] test(contributors-search): add massive scaling coverage --- ...ontributorsSearch.massive-scaling.test.tsx | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 app/contributors/ContributorsSearch.massive-scaling.test.tsx diff --git a/app/contributors/ContributorsSearch.massive-scaling.test.tsx b/app/contributors/ContributorsSearch.massive-scaling.test.tsx new file mode 100644 index 000000000..d92603cf1 --- /dev/null +++ b/app/contributors/ContributorsSearch.massive-scaling.test.tsx @@ -0,0 +1,117 @@ +import React from 'react'; +import { describe, it, expect, vi } from 'vitest'; +import { render, screen, fireEvent } from '@testing-library/react'; +import ContributorsSearch from './ContributorsSearch'; + +vi.mock('next/link', () => ({ + default: ({ children, href, ...props }: React.AnchorHTMLAttributes) => ( + + {children} + + ), +})); + +vi.mock('next/image', () => ({ + default: (props: React.ImgHTMLAttributes) => {props.alt}, +})); + +vi.mock('framer-motion', () => ({ + motion: { + div: ({ children, ...props }: React.HTMLAttributes) => ( +
{children}
+ ), + }, + AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}, +})); + +const createContributors = (count: number) => + Array.from({ length: count }, (_, index) => ({ + id: index + 1, + login: `contributor-${index}`, + avatar_url: `https://example.com/avatar-${index}.png`, + contributions: index * 10, + html_url: `https://github.com/contributor-${index}`, + })); + +describe('ContributorsSearch massive scaling', () => { + it('renders thousands of contributors without crashing', () => { + const contributors = createContributors(2000); + + render(); + + expect(screen.getByText('2000 of 2000 contributors')).toBeInTheDocument(); + + expect(screen.getByText('contributor-0')).toBeInTheDocument(); + expect(screen.getByText('contributor-1999')).toBeInTheDocument(); + }); + + it('filters correctly within a large contributor dataset', () => { + const contributors = createContributors(3000); + + render(); + + const input = screen.getByRole('textbox'); + + fireEvent.change(input, { + target: { + value: 'contributor-2999', + }, + }); + + expect(screen.getByText('1 of 3000 contributors')).toBeInTheDocument(); + + expect(screen.getByText('contributor-2999')).toBeInTheDocument(); + }); + + it('renders a large number of profile cards while preserving layout structure', () => { + const contributors = createContributors(1000); + + const { container } = render(); + + const links = container.querySelectorAll('a[href]'); + + expect(links.length).toBe(1000); + + const grid = container.querySelector('.grid.grid-cols-1'); + + expect(grid).toBeInTheDocument(); + }); + + it('shows no-results state efficiently on large datasets', () => { + const contributors = createContributors(5000); + + render(); + + fireEvent.change(screen.getByRole('textbox'), { + target: { + value: 'non-existent-user-999999', + }, + }); + + expect(screen.getByText('No architects found')).toBeInTheDocument(); + + expect(screen.getByText(/Try a different search query/i)).toBeInTheDocument(); + }); + + it('maintains acceptable filtering performance under high-volume searches', () => { + const contributors = createContributors(5000); + + render(); + + const input = screen.getByRole('textbox'); + + const start = performance.now(); + + fireEvent.change(input, { + target: { + value: 'contributor-4999', + }, + }); + + const duration = performance.now() - start; + + expect(duration).toBeLessThan(1000); + + expect(screen.getByText('contributor-4999')).toBeInTheDocument(); + }); +});