feat: add CI/CD, code quality, testing and security hardening
CI / quality (push) Failing after 6m22s
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1959ddb41a
commit
e9690a49f9
@@ -0,0 +1,236 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type {
|
||||
SubjectProgress,
|
||||
ModuleDetail,
|
||||
CourseComplianceReport
|
||||
} from '../../../src/shared/coach'
|
||||
|
||||
const drawShape = vi.fn()
|
||||
vi.mock('../../../src/renderer/src/components/drawRoughShapes', () => ({ drawShape }))
|
||||
vi.mock('roughjs', () => ({ default: { canvas: vi.fn(() => ({})) } }))
|
||||
const mermaidRender = vi.fn(async () => ({ svg: '<svg></svg>' }))
|
||||
vi.mock('mermaid', () => ({ default: { initialize: vi.fn(), render: mermaidRender } }))
|
||||
|
||||
let navigateCallback: ((payload: { subject: string; module: string }) => void) | undefined
|
||||
const getCoachProgress = vi.fn()
|
||||
const getModuleDetail = vi.fn()
|
||||
const getCourseCompliance = vi.fn(async (): Promise<CourseComplianceReport | null> => null)
|
||||
const requestModuleEvaluation = vi.fn()
|
||||
|
||||
function setupWindowApi(): void {
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
getCoachProgress,
|
||||
getModuleDetail,
|
||||
getCourseCompliance,
|
||||
requestModuleEvaluation,
|
||||
onNavigateToModule: vi.fn((cb: (payload: { subject: string; module: string }) => void) => {
|
||||
navigateCallback = cb
|
||||
return () => {}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const { default: CoachProgressView } =
|
||||
await import('../../../src/renderer/src/components/CoachProgressView')
|
||||
|
||||
const SUBJECT: SubjectProgress = {
|
||||
subject: 'algebre',
|
||||
level: 'debutant',
|
||||
status: 'in_progress',
|
||||
objective: 'Tu seras capable de resoudre une equation',
|
||||
lastSessionAt: new Date().toISOString(),
|
||||
concepts: [
|
||||
{
|
||||
name: 'Module A',
|
||||
status: 'acquired',
|
||||
lastReviewedAt: new Date().toISOString(),
|
||||
nextReviewAt: null,
|
||||
locked: false,
|
||||
orderIndex: 0
|
||||
},
|
||||
{
|
||||
name: 'Module B',
|
||||
status: 'not_started',
|
||||
lastReviewedAt: new Date().toISOString(),
|
||||
nextReviewAt: null,
|
||||
locked: true,
|
||||
orderIndex: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const MODULE_DETAIL: ModuleDetail = {
|
||||
name: 'Module A',
|
||||
status: 'acquired',
|
||||
locked: false,
|
||||
theorySummary: 'Contenu du module.',
|
||||
assessments: [
|
||||
{
|
||||
question: 'Question 1 ?',
|
||||
answer: 'Reponse',
|
||||
dontKnow: false,
|
||||
difficulty: 'facile',
|
||||
exerciseStyle: 'prediction',
|
||||
targetsCommonError: null,
|
||||
createdAt: new Date().toISOString()
|
||||
}
|
||||
],
|
||||
diagrams: []
|
||||
}
|
||||
|
||||
describe('<CoachProgressView />', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
setupWindowApi()
|
||||
getCoachProgress.mockResolvedValue([SUBJECT])
|
||||
getModuleDetail.mockResolvedValue(MODULE_DETAIL)
|
||||
getCourseCompliance.mockResolvedValue(null)
|
||||
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({
|
||||
clearRect: vi.fn()
|
||||
} as unknown as CanvasRenderingContext2D)
|
||||
})
|
||||
|
||||
it('should show a loading state before subjects arrive', () => {
|
||||
getCoachProgress.mockReturnValue(new Promise(() => {}))
|
||||
render(<CoachProgressView />)
|
||||
expect(screen.getByText('Chargement...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should list the loaded subjects', async () => {
|
||||
render(<CoachProgressView />)
|
||||
expect(await screen.findByText('algebre')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show an empty state when there are no subjects yet', async () => {
|
||||
getCoachProgress.mockResolvedValue([])
|
||||
render(<CoachProgressView />)
|
||||
expect(await screen.findByText(/Aucun sujet d.apprentissage/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should navigate to the modules view and list each module', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
expect(screen.getByText('Module A')).toBeInTheDocument()
|
||||
expect(screen.getByText('Module B')).toBeInTheDocument()
|
||||
expect(screen.getByText(/Niveau : debutant/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/resoudre une equation/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should disable a locked module button', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
expect(screen.getByText('Module B').closest('button')).toBeDisabled()
|
||||
})
|
||||
|
||||
it('should show the compliance checklist once loaded', async () => {
|
||||
getCourseCompliance.mockResolvedValue({
|
||||
subject: 'algebre',
|
||||
checks: [
|
||||
{ key: 'sources', label: 'Recherche sourcee', ok: true, detail: 'ok' },
|
||||
{ key: 'objective', label: 'Objectif mesurable', ok: false, detail: 'manquant' }
|
||||
]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await waitFor(() => expect(screen.getByText(/1\/2/)).toBeInTheDocument())
|
||||
})
|
||||
|
||||
it('should navigate to a module detail view and show its content', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
expect(await screen.findByText('Contenu du module.')).toBeInTheDocument()
|
||||
expect(screen.getByText('Question 1 ?')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the "evaluer ce module" button for an unlocked, unacquired module', async () => {
|
||||
getModuleDetail.mockResolvedValue({ ...MODULE_DETAIL, status: 'in_progress' })
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
const evalButton = await screen.findByText('Evaluer ce module')
|
||||
await user.click(evalButton)
|
||||
expect(requestModuleEvaluation).toHaveBeenCalledWith('algebre', 'Module A')
|
||||
})
|
||||
|
||||
it('should not show the evaluation button once the module is acquired', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
await screen.findByText('Contenu du module.')
|
||||
expect(screen.queryByText('Evaluer ce module')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should navigate directly to a module detail view on an incoming navigate-to-module event', async () => {
|
||||
render(<CoachProgressView />)
|
||||
await waitFor(() => expect(navigateCallback).toBeDefined())
|
||||
navigateCallback?.({ subject: 'algebre', module: 'Module A' })
|
||||
expect(await screen.findByText('Contenu du module.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render a shapes diagram for a module', async () => {
|
||||
getModuleDetail.mockResolvedValue({
|
||||
...MODULE_DETAIL,
|
||||
diagrams: [
|
||||
{
|
||||
kind: 'shapes',
|
||||
title: 'Mon schema',
|
||||
data: { title: 'Mon schema', width: 400, height: 300, shapes: [] },
|
||||
createdAt: new Date().toISOString()
|
||||
}
|
||||
]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
expect(await screen.findByText('Mon schema')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render a mermaid diagram for a module', async () => {
|
||||
getModuleDetail.mockResolvedValue({
|
||||
...MODULE_DETAIL,
|
||||
diagrams: [
|
||||
{
|
||||
kind: 'mermaid',
|
||||
title: 'Mon diagramme',
|
||||
data: { mermaidCode: 'graph LR; A --> B' },
|
||||
createdAt: new Date().toISOString()
|
||||
}
|
||||
]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
expect(await screen.findByText('Mon diagramme')).toBeInTheDocument()
|
||||
await waitFor(() => expect(mermaidRender).toHaveBeenCalled())
|
||||
})
|
||||
|
||||
it('should go back from the module view to the modules list', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText('Module A'))
|
||||
await screen.findByText('Contenu du module.')
|
||||
await user.click(screen.getByText(/Retour aux modules/))
|
||||
expect(screen.getByText('Module A')).toBeInTheDocument()
|
||||
expect(screen.getByText('Module B')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should go back from the modules view to the subjects list', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CoachProgressView />)
|
||||
await user.click(await screen.findByText('algebre'))
|
||||
await user.click(screen.getByText(/Retour aux sujets/))
|
||||
expect(await screen.findByText('algebre')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user