feat(simulations): router /sujets + SimulationFlowProvider wiring + useSimulation refacto
This commit is contained in:
parent
782439b309
commit
a6f95c2093
4 changed files with 87 additions and 116 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Transitions couvertes :
|
||||
* idle → choosing-subject (selectTask success, tâche avec catalogue)
|
||||
* choosing-subject → task-selected (selectRandom / selectSujet)
|
||||
* choosing-subject → task-selected (selectSujet)
|
||||
* task-selected → correcting (submitText déclenché)
|
||||
* correcting → done (correctEe success)
|
||||
* correcting → task-selected (correctEe error)
|
||||
|
|
@ -13,9 +13,11 @@
|
|||
|
||||
import { renderHook, act, waitFor } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import React from 'react'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { useSimulation } from '../useSimulation'
|
||||
import { SimulationFlowProvider } from '../../state/SimulationFlowProvider'
|
||||
import { createSimulation } from '@/entities/production/api'
|
||||
import { correctEe } from '@/entities/report/api'
|
||||
import type { Production } from '@/entities/production/types'
|
||||
|
|
@ -35,6 +37,17 @@ const mockProduction: Production = {
|
|||
sujet: null,
|
||||
}
|
||||
|
||||
const mockSujet = {
|
||||
id: 'sujet-1',
|
||||
consigne: 'Rédigez une lettre.',
|
||||
role: null,
|
||||
contexte: null,
|
||||
doc1_titre: null,
|
||||
doc1_texte: null,
|
||||
doc2_titre: null,
|
||||
doc2_texte: null,
|
||||
}
|
||||
|
||||
const mockReport: Report = {
|
||||
simulation_id: 'sim-1',
|
||||
score: 80,
|
||||
|
|
@ -52,7 +65,15 @@ function createWrapper() {
|
|||
defaultOptions: { mutations: { retry: false } },
|
||||
})
|
||||
return function Wrapper({ children }: { children: React.ReactNode }) {
|
||||
return React.createElement(QueryClientProvider, { client: queryClient }, children)
|
||||
return React.createElement(
|
||||
MemoryRouter,
|
||||
null,
|
||||
React.createElement(
|
||||
QueryClientProvider,
|
||||
{ client: queryClient },
|
||||
React.createElement(SimulationFlowProvider, null, children),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +146,7 @@ describe('useSimulation — submitText', () => {
|
|||
|
||||
act(() => result.current.selectTask({ tache: 'EE_T1', mode: 'entrainement' }))
|
||||
await waitFor(() => expect(result.current.step).toBe('choosing-subject'))
|
||||
act(() => result.current.selectRandom([]))
|
||||
act(() => result.current.selectSujet(mockSujet))
|
||||
await waitFor(() => expect(result.current.step).toBe('task-selected'))
|
||||
|
||||
act(() => result.current.submitText('Mon texte de production.'))
|
||||
|
|
@ -144,7 +165,7 @@ describe('useSimulation — submitText', () => {
|
|||
|
||||
act(() => result.current.selectTask({ tache: 'EE_T1', mode: 'entrainement' }))
|
||||
await waitFor(() => expect(result.current.step).toBe('choosing-subject'))
|
||||
act(() => result.current.selectRandom([]))
|
||||
act(() => result.current.selectSujet(mockSujet))
|
||||
await waitFor(() => expect(result.current.step).toBe('task-selected'))
|
||||
|
||||
act(() => result.current.submitText('Mon texte.')
|
||||
|
|
@ -171,7 +192,7 @@ describe('useSimulation — reset', () => {
|
|||
|
||||
act(() => result.current.selectTask({ tache: 'EE_T1', mode: 'entrainement' }))
|
||||
await waitFor(() => expect(result.current.step).toBe('choosing-subject'))
|
||||
act(() => result.current.selectRandom([]))
|
||||
act(() => result.current.selectSujet(mockSujet))
|
||||
await waitFor(() => expect(result.current.step).toBe('task-selected'))
|
||||
|
||||
act(() => result.current.reset())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue