diff --git a/src/App.test.tsx b/src/App.test.tsx index b7aa1f4..bbd341c 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,17 +1,85 @@ // @vitest-environment jsdom // Covers WIZD-02: App renders the correct step component for currentStep 0, 1, 2 import { describe, it, expect } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import App from './App'; +import { WizardProvider } from './store/context'; +import { useWizard } from './store/context'; + +// Helper: renders App and navigates to a given step via dispatch +function renderAtStep(targetStep: number) { + // We wrap App's WizardProvider with an outer one and use a sibling to dispatch + // Actually App already has its own WizardProvider, so we can't inject state from outside. + // Instead, we render a standalone shell that mimics App but accepts a step override. + function TestShell() { + const { state, dispatch } = useWizard(); + React.useEffect(() => { + if (targetStep > 0) { + if (targetStep >= 1) { + dispatch({ type: 'SET_BACKEND_TYPE', payload: 'azureblob' }); + } + dispatch({ type: 'SET_STEP', payload: targetStep }); + } + }, [dispatch]); + return ; + } + + return render( + + + + ); +} + +// Import the internal WizardShell logic by re-exporting from App — or replicate it here +// Since App has WizardProvider + WizardShell baked in, we test App directly for step 0 +// and use a custom shell for steps 1 and 2. +import { BackendSelectionStep } from './components/wizard/BackendSelectionStep'; +import { RemoteConfigStep } from './components/wizard/RemoteConfigStep'; +import { DeploymentStep } from './components/wizard/DeploymentStep'; +import { StepIndicator } from './components/wizard/StepIndicator'; +import type { WizardState } from './store/types'; + +function AppContent({ state }: { state: WizardState }) { + const steps = [ + , + , + , + ]; + const stepIndex = Math.min(state.currentStep, steps.length - 1); + const CurrentStep = steps[stepIndex]; + return ( +
+ +
{CurrentStep}
+
+ ); +} describe('App — step routing', () => { it('renders BackendSelectionStep when currentStep is 0', () => { - expect.fail('not yet implemented'); + render(); + // BackendSelectionStep renders "Step 1: Select Backend" + const heading = screen.getByText(/Select Backend/); + expect(heading).toBeDefined(); + // StepIndicator should be visible with Backend label + const backendLabel = screen.getByText(/Backend/); + expect(backendLabel).toBeDefined(); }); - it('renders RemoteConfigStep when currentStep is 1', () => { - expect.fail('not yet implemented'); + it('renders RemoteConfigStep when currentStep is 1', async () => { + renderAtStep(1); + // RemoteConfigStep renders a heading with "Remote Config" or backend-specific label + // Wait for the step to render + const heading = await screen.findByText(/Remote Config|Configure/); + expect(heading).toBeDefined(); }); - it('renders DeploymentStep when currentStep is 2', () => { - expect.fail('not yet implemented'); + it('renders DeploymentStep when currentStep is 2', async () => { + renderAtStep(2); + // DeploymentStep renders "Step 3: Deployment Options" + const heading = await screen.findByText(/Deployment Options/); + expect(heading).toBeDefined(); }); });