|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, expect, it, vi } from 'vitest'; |
| 4 | +import FileTree from './FileTree'; |
| 5 | +import type { FileNode } from '../types'; |
| 6 | + |
| 7 | +vi.mock('react-virtuoso', () => ({ |
| 8 | + Virtuoso: ({ data, itemContent }: any) => ( |
| 9 | + <div data-testid="virtuoso" data-count={String(data.length)}> |
| 10 | + {data.slice(0, 12).map((item: any, index: number) => ( |
| 11 | + <div key={item.path}>{itemContent(index, item)}</div> |
| 12 | + ))} |
| 13 | + </div> |
| 14 | + ), |
| 15 | +})); |
| 16 | + |
| 17 | +const makeLargeTree = (): FileNode[] => [ |
| 18 | + { |
| 19 | + name: 'src', |
| 20 | + path: 'src', |
| 21 | + isDirectory: true, |
| 22 | + children: Array.from({ length: 200 }, (_, index) => ({ |
| 23 | + name: `file-${index}.ts`, |
| 24 | + path: `src/file-${index}.ts`, |
| 25 | + isDirectory: false, |
| 26 | + children: [], |
| 27 | + status: 'processed' as const, |
| 28 | + })), |
| 29 | + }, |
| 30 | +]; |
| 31 | + |
| 32 | +describe('FileTree virtualization', () => { |
| 33 | + it('passes the flattened visible rows into the virtual list instead of mounting the full tree', () => { |
| 34 | + render( |
| 35 | + <FileTree |
| 36 | + nodes={makeLargeTree()} |
| 37 | + onFileSelect={vi.fn()} |
| 38 | + onDeleteFile={vi.fn()} |
| 39 | + onCopyPath={vi.fn()} |
| 40 | + onToggleExclude={vi.fn()} |
| 41 | + selectedFilePath={null} |
| 42 | + showCharCount={false} |
| 43 | + /> |
| 44 | + ); |
| 45 | + |
| 46 | + expect(screen.getByTestId('virtuoso').getAttribute('data-count')).toBe('201'); |
| 47 | + expect(screen.getByText('file-0.ts')).not.toBeNull(); |
| 48 | + expect(screen.queryByText('file-199.ts')).toBeNull(); |
| 49 | + }); |
| 50 | +}); |
0 commit comments