import { fireEvent, screen } from '@testing-library/react' import { describe, expect, test, vi } from 'vitest' import { SteppedFlow, SteppedFlowHeader } from './SteppedFlow' import { customRender } from '@/tests/lib/custom-render' const steps = [ { id: 'destination', label: 'Destination' }, { id: 'connection', label: 'Connection' }, { id: 'review', label: 'Review' }, ] describe('SteppedFlow', () => { test('offers Cancel instead of Back on the first step, and advances when onNext is omitted', () => { const onCancel = vi.fn() const onStepChange = vi.fn() customRender( Step body ) expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument() fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) expect(onCancel).toHaveBeenCalledOnce() fireEvent.click(screen.getByRole('button', { name: 'Next' })) expect(onStepChange).toHaveBeenCalledWith('connection') }) test('offers Back instead of Cancel after the first step', () => { const onStepChange = vi.fn() customRender( Step body ) expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument() fireEvent.click(screen.getByRole('button', { name: 'Back' })) expect(onStepChange).toHaveBeenCalledWith('destination') }) test('shows the final action on the last step instead of Next', () => { const onFinal = vi.fn() customRender( Step body ) expect(screen.queryByRole('button', { name: /Next/ })).not.toBeInTheDocument() fireEvent.click(screen.getByRole('button', { name: 'Create and start pipeline' })) expect(onFinal).toHaveBeenCalledOnce() }) test('renders a step header with its heading, description and optional actions', () => { customRender( Docs } /> ) expect(screen.getByRole('heading', { name: 'Choose a destination' })).toBeInTheDocument() expect(screen.getByText('Where should data go?')).toBeInTheDocument() expect(screen.getByRole('button', { name: 'Docs' })).toBeInTheDocument() }) test('disables Back and the final action while navigation is locked', () => { customRender( Step body ) expect(screen.getByRole('button', { name: 'Back' })).toBeDisabled() expect(screen.getByRole('button', { name: 'Create and start pipeline' })).toBeDisabled() }) test('disables Next while navigation is locked', () => { customRender( Step body ) expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled() }) })