|
| 1 | +import { describe, it, expect, vi, beforeEach } from 'vitest'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | +import OnboardingFlow from '../../components/OnboardingFlow'; |
| 4 | +import type { YouTubeVideo } from '../../components/YouTubeGrid'; |
| 5 | +import type { Highlight } from '../../components/HighlightCard'; |
| 6 | + |
| 7 | +const sampleVideos: YouTubeVideo[] = [ |
| 8 | + { id: 'v1', title: 'Video One', thumbnail: 'https://example.com/1.jpg', privacyStatus: 'public' }, |
| 9 | + { id: 'v2', title: 'Video Two', thumbnail: 'https://example.com/2.jpg', privacyStatus: 'public' }, |
| 10 | +]; |
| 11 | + |
| 12 | +const sampleHighlights: Highlight[] = [ |
| 13 | + { timestamp: '0:15', description: 'Laughing together', expression: 'joyful' }, |
| 14 | +]; |
| 15 | + |
| 16 | +const sampleCrops = [ |
| 17 | + 'https://example.com/crop1.jpg', |
| 18 | + 'https://example.com/crop2.jpg', |
| 19 | +]; |
| 20 | + |
| 21 | +const makeDefaultProps = () => ({ |
| 22 | + stage: 'welcome' as const, |
| 23 | + videos: sampleVideos, |
| 24 | + personCrops: sampleCrops, |
| 25 | + highlights: sampleHighlights, |
| 26 | + analysisStep: 'Extracting features...', |
| 27 | + analysisPercent: 30, |
| 28 | + onSelectVideo: vi.fn(), |
| 29 | + onSelectPerson: vi.fn(), |
| 30 | +}); |
| 31 | + |
| 32 | +let defaultProps: ReturnType<typeof makeDefaultProps>; |
| 33 | + |
| 34 | +beforeEach(() => { |
| 35 | + defaultProps = makeDefaultProps(); |
| 36 | +}); |
| 37 | + |
| 38 | +describe('OnboardingFlow', () => { |
| 39 | + it('renders YouTubeGrid when stage is youtube_grid', () => { |
| 40 | + render(<OnboardingFlow {...defaultProps} stage="youtube_grid" />); |
| 41 | + expect(screen.getByText('Select a video')).toBeInTheDocument(); |
| 42 | + expect(screen.getByText('Video One')).toBeInTheDocument(); |
| 43 | + expect(screen.getByText('Video Two')).toBeInTheDocument(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('renders person select UI when stage is person_select with crops', () => { |
| 47 | + render(<OnboardingFlow {...defaultProps} stage="person_select" />); |
| 48 | + expect(screen.getByText('Select the person to analyze')).toBeInTheDocument(); |
| 49 | + expect(screen.getByAltText('Person 1')).toBeInTheDocument(); |
| 50 | + expect(screen.getByAltText('Person 2')).toBeInTheDocument(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('does not render person select when personCrops is empty', () => { |
| 54 | + render(<OnboardingFlow {...defaultProps} stage="person_select" personCrops={[]} />); |
| 55 | + expect(screen.queryByText('Select the person to analyze')).not.toBeInTheDocument(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('renders ProgressBar when stage is analyzing', () => { |
| 59 | + render(<OnboardingFlow {...defaultProps} stage="analyzing" />); |
| 60 | + expect(screen.getByText('Extracting features...')).toBeInTheDocument(); |
| 61 | + expect(screen.getByText('30%')).toBeInTheDocument(); |
| 62 | + }); |
| 63 | + |
| 64 | + it('calls onSelectPerson when person button clicked', () => { |
| 65 | + const onSelectPerson = vi.fn(); |
| 66 | + render( |
| 67 | + <OnboardingFlow {...defaultProps} stage="person_select" onSelectPerson={onSelectPerson} /> |
| 68 | + ); |
| 69 | + fireEvent.click(screen.getByAltText('Person 2')); |
| 70 | + expect(onSelectPerson).toHaveBeenCalledWith(1); |
| 71 | + }); |
| 72 | +}); |
0 commit comments