diff --git a/components/dashboard/PRInsights/Highlights.massive-scaling.test.tsx b/components/dashboard/PRInsights/Highlights.massive-scaling.test.tsx new file mode 100644 index 000000000..daeba1dc8 --- /dev/null +++ b/components/dashboard/PRInsights/Highlights.massive-scaling.test.tsx @@ -0,0 +1,124 @@ +import React from 'react'; +import { describe, expect, it, vi } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import Highlights from './Highlights'; +import type { PRInsightData } from '@/services/github/pr-insights'; + +vi.mock('framer-motion', () => ({ + motion: { + a: ({ + children, + className, + href, + target, + rel, + ...props + }: React.AnchorHTMLAttributes & { children?: React.ReactNode }) => { + const validProps = Object.keys(props).reduce( + (acc, key) => { + if (!['initial', 'animate', 'transition', 'whileInView', 'viewport'].includes(key)) { + acc[key] = (props as Record)[key]; + } + return acc; + }, + {} as Record + ); + return ( + + {children} + + ); + }, + }, +})); + +vi.mock('lucide-react', () => ({ + MessageSquare: () => , + Zap: () => , + HardDrive: () => , + ArrowRight: () => , +})); + +function buildMassiveHighlights( + overrides: Partial = {} +): PRInsightData['highlights'] { + return { + fastestMerged: { + title: 'A'.repeat(10000), + url: 'https://github.com/org/repo/pull/1', + time: 0.001, + }, + mostDiscussed: { + title: 'B'.repeat(10000), + url: 'https://github.com/org/repo/pull/2', + comments: 999999, + }, + largest: { + title: 'C'.repeat(10000), + url: 'https://github.com/org/repo/pull/3', + additions: 999999, + deletions: 888888, + }, + ...overrides, + }; +} + +describe('Highlights Massive Data Sets and Extreme High Bounds Scaling', () => { + it('renders all three cards with extreme high bounds values without layout breakage', () => { + render(); + + expect(screen.getByText('Fastest Merged PR')).toBeInTheDocument(); + expect(screen.getByText('Most Discussed')).toBeInTheDocument(); + expect(screen.getByText('Largest Impact')).toBeInTheDocument(); + + expect(screen.getByText('0.0 hrs')).toBeInTheDocument(); + expect(screen.getByText(/999999.*comments/)).toBeInTheDocument(); + expect(screen.getByText('+999999 -888888')).toBeInTheDocument(); + }); + + it('renders extremely long PR titles without crashing using line-clamp', () => { + const { container } = render(); + + const clampedElements = container.querySelectorAll('.line-clamp-2'); + expect(clampedElements.length).toBeGreaterThan(0); + + clampedElements.forEach((el) => { + expect(el.textContent?.length).toBeGreaterThan(0); + }); + }); + + it('renders gracefully when all highlight fields are undefined', () => { + render( + + ); + + expect(screen.getAllByText('N/A')).toHaveLength(3); + expect(screen.getAllByText('No data available')).toHaveLength(3); + }); + + it('all card links point to correct URLs under massive data', () => { + render(); + + const links = screen.getAllByRole('link'); + expect(links).toHaveLength(3); + + expect(links[0]).toHaveAttribute('href', 'https://github.com/org/repo/pull/1'); + expect(links[1]).toHaveAttribute('href', 'https://github.com/org/repo/pull/2'); + expect(links[2]).toHaveAttribute('href', 'https://github.com/org/repo/pull/3'); + }); + + it('falls back to # href when highlight data is undefined', () => { + render( + + ); + + const links = screen.getAllByRole('link'); + links.forEach((link) => { + expect(link).toHaveAttribute('href', '#'); + }); + }); +});