|
| 1 | +import type React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, expect, it, vi } from 'vitest'; |
| 4 | + |
| 5 | +import { BoxIcon, CheckIcon, CloseIcon, CopyIcon, ZapIcon } from './Icons'; |
| 6 | + |
| 7 | +type IconProps = React.SVGProps<SVGSVGElement>; |
| 8 | + |
| 9 | +vi.mock('lucide-react', () => ({ |
| 10 | + Copy: (props: IconProps) => <svg data-testid="copy-icon" {...props} />, |
| 11 | + Zap: (props: IconProps) => <svg data-testid="zap-icon" {...props} />, |
| 12 | + Box: (props: IconProps) => <svg data-testid="box-icon" {...props} />, |
| 13 | + Check: (props: IconProps) => <svg data-testid="check-icon" {...props} />, |
| 14 | + X: (props: IconProps) => <svg data-testid="close-icon" {...props} />, |
| 15 | +})); |
| 16 | + |
| 17 | +describe('Icons massive scaling behavior', () => { |
| 18 | + it('renders 500 CopyIcon instances without crashing', () => { |
| 19 | + render( |
| 20 | + <> |
| 21 | + {Array.from({ length: 500 }, (_, index) => ( |
| 22 | + <CopyIcon key={index} /> |
| 23 | + ))} |
| 24 | + </> |
| 25 | + ); |
| 26 | + |
| 27 | + expect(screen.getAllByTestId('copy-icon')).toHaveLength(500); |
| 28 | + }); |
| 29 | + |
| 30 | + it('renders 500 ZapIcon instances without crashing', () => { |
| 31 | + render( |
| 32 | + <> |
| 33 | + {Array.from({ length: 500 }, (_, index) => ( |
| 34 | + <ZapIcon key={index} /> |
| 35 | + ))} |
| 36 | + </> |
| 37 | + ); |
| 38 | + |
| 39 | + expect(screen.getAllByTestId('zap-icon')).toHaveLength(500); |
| 40 | + }); |
| 41 | + |
| 42 | + it('renders mixed icon sets at high volume', () => { |
| 43 | + render( |
| 44 | + <> |
| 45 | + {Array.from({ length: 100 }, (_, index) => ( |
| 46 | + <div key={index}> |
| 47 | + <CopyIcon /> |
| 48 | + <ZapIcon /> |
| 49 | + <BoxIcon /> |
| 50 | + <CheckIcon /> |
| 51 | + <CloseIcon /> |
| 52 | + </div> |
| 53 | + ))} |
| 54 | + </> |
| 55 | + ); |
| 56 | + |
| 57 | + expect(screen.getAllByTestId('copy-icon')).toHaveLength(100); |
| 58 | + expect(screen.getAllByTestId('zap-icon')).toHaveLength(100); |
| 59 | + expect(screen.getAllByTestId('box-icon')).toHaveLength(100); |
| 60 | + expect(screen.getAllByTestId('check-icon')).toHaveLength(100); |
| 61 | + expect(screen.getAllByTestId('close-icon')).toHaveLength(100); |
| 62 | + }); |
| 63 | + |
| 64 | + it('preserves icon dimension attributes across many rendered icons', () => { |
| 65 | + render( |
| 66 | + <> |
| 67 | + {Array.from({ length: 100 }, (_, index) => ( |
| 68 | + <CopyIcon key={index} /> |
| 69 | + ))} |
| 70 | + </> |
| 71 | + ); |
| 72 | + |
| 73 | + expect( |
| 74 | + screen.getAllByTestId('copy-icon').every((icon) => icon.getAttribute('width') === '20') |
| 75 | + ).toBe(true); |
| 76 | + }); |
| 77 | + |
| 78 | + it('preserves CheckIcon stroke styling across high-volume renders', () => { |
| 79 | + render( |
| 80 | + <> |
| 81 | + {Array.from({ length: 100 }, (_, index) => ( |
| 82 | + <CheckIcon key={index} /> |
| 83 | + ))} |
| 84 | + </> |
| 85 | + ); |
| 86 | + |
| 87 | + expect( |
| 88 | + screen.getAllByTestId('check-icon').every((icon) => icon.getAttribute('stroke') === '#10b981') |
| 89 | + ).toBe(true); |
| 90 | + }); |
| 91 | +}); |
0 commit comments