CI / quality (push) Failing after 6m22s
Implements Max_Code_Quality_CICD_Production.md: TypeScript strict mode, ESLint flat config with type-checking and security plugin, Prettier, Husky + lint-staged, Vitest with 80%+ coverage (473 tests), Playwright e2e, Electron security hardening (contextIsolation, CSP, IPC validation), electron-builder + electron-updater, Dockerfile, Gitea Actions CI/release workflows, and SonarQube docker-compose setup. Also fixes two real bugs found while writing tests: unawaited clipboard promises and a mermaid container ref timing issue in CoachDrawingView. Fixes lint-staged on Windows/Node 24 by invoking eslint/prettier via `node <bin>.js` instead of their .cmd shims, which Node's child_process now refuses to spawn without shell:true. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, act } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { ExerciseForm } from '../../../src/shared/coach'
|
|
|
|
let onFormCallback: ((form: ExerciseForm) => void) | undefined
|
|
const submitWrittenForm = vi.fn()
|
|
|
|
function setupWindowApi(): void {
|
|
;(window as unknown as { api: Record<string, unknown> }).api = {
|
|
onAskWrittenForm: vi.fn((cb: (form: ExerciseForm) => void) => {
|
|
onFormCallback = cb
|
|
return () => {}
|
|
}),
|
|
submitWrittenForm
|
|
}
|
|
}
|
|
|
|
const { default: CoachExerciseView } =
|
|
await import('../../../src/renderer/src/components/CoachExerciseView')
|
|
|
|
const FORM: ExerciseForm = {
|
|
requestId: 'req-1',
|
|
items: [
|
|
{
|
|
id: '0',
|
|
question: 'Quelle est la capitale de la France ?',
|
|
type: 'free_text',
|
|
options: null
|
|
},
|
|
{ id: '1', question: 'Vrai ou faux : 2+2=4', type: 'true_false', options: null },
|
|
{ id: '2', question: 'Choisis la bonne reponse', type: 'multiple_choice', options: ['A', 'B'] }
|
|
]
|
|
}
|
|
|
|
describe('<CoachExerciseView />', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
setupWindowApi()
|
|
})
|
|
|
|
it('should show a waiting message before any form is received', () => {
|
|
render(<CoachExerciseView />)
|
|
expect(screen.getByText(/En attente de questions/)).toBeInTheDocument()
|
|
})
|
|
|
|
it('should display every question once a form is received', () => {
|
|
render(<CoachExerciseView />)
|
|
act(() => onFormCallback?.(FORM))
|
|
expect(screen.getByText(/capitale de la France/)).toBeInTheDocument()
|
|
expect(screen.getByText(/2\+2=4/)).toBeInTheDocument()
|
|
expect(screen.getByText(/bonne reponse/)).toBeInTheDocument()
|
|
})
|
|
|
|
it('should keep the submit button disabled until every question is answered', async () => {
|
|
const user = userEvent.setup()
|
|
render(<CoachExerciseView />)
|
|
act(() => onFormCallback?.(FORM))
|
|
|
|
const submitButton = screen.getByText('Soumettre tout le formulaire')
|
|
expect(submitButton).toBeDisabled()
|
|
|
|
await user.type(screen.getByRole('textbox'), 'Paris')
|
|
await user.click(screen.getByText('Vrai'))
|
|
await user.click(screen.getByText('A'))
|
|
|
|
expect(submitButton).toBeEnabled()
|
|
})
|
|
|
|
it('should allow answering "Je ne sais pas" to satisfy a question', async () => {
|
|
const user = userEvent.setup()
|
|
render(<CoachExerciseView />)
|
|
act(() => onFormCallback?.({ requestId: 'req-2', items: [FORM.items[0]!] }))
|
|
|
|
const submitButton = screen.getByText('Soumettre tout le formulaire')
|
|
expect(submitButton).toBeDisabled()
|
|
await user.click(screen.getByText('Je ne sais pas'))
|
|
expect(submitButton).toBeEnabled()
|
|
})
|
|
|
|
it('should submit all answers and show the confirmation message', async () => {
|
|
const user = userEvent.setup()
|
|
render(<CoachExerciseView />)
|
|
act(() => onFormCallback?.(FORM))
|
|
|
|
await user.type(screen.getByRole('textbox'), 'Paris')
|
|
await user.click(screen.getByText('Vrai'))
|
|
await user.click(screen.getByText('A'))
|
|
await user.click(screen.getByText('Soumettre tout le formulaire'))
|
|
|
|
expect(submitWrittenForm).toHaveBeenCalledWith('req-1', [
|
|
{ id: '0', answer: 'Paris' },
|
|
{ id: '1', answer: 'Vrai' },
|
|
{ id: '2', answer: 'A' }
|
|
])
|
|
expect(screen.getByText(/Reponses envoyees a Max/)).toBeInTheDocument()
|
|
})
|
|
|
|
it('should reset state and show a fresh form when a second form arrives', () => {
|
|
render(<CoachExerciseView />)
|
|
act(() => onFormCallback?.(FORM))
|
|
act(() =>
|
|
onFormCallback?.({
|
|
requestId: 'req-3',
|
|
items: [{ id: '0', question: 'Autre question', type: 'free_text', options: null }]
|
|
})
|
|
)
|
|
expect(screen.getByText(/Autre question/)).toBeInTheDocument()
|
|
expect(screen.queryByText(/capitale de la France/)).not.toBeInTheDocument()
|
|
})
|
|
})
|