Files
williamandClaude Sonnet 5 1c2f002eb3 refactor: move app code into Max Avatar/ subfolder (monorepo prep for backend)
Step 1 of adding a backend proxy server (API keys held server-side instead
of shipped in the installer). Moves everything app-specific into
"Max Avatar/" via git mv (preserves history): src/, tests/, scripts/,
assets/, build/, resources/, package.json/-lock.json, electron-builder.yml,
electron.vite.config.ts, eslint.config.mjs, playwright.config.ts,
vitest.config.mts, sonar-project.properties, tsconfig*.json, Dockerfile,
.editorconfig/.env*/.gitignore/.prettier*.

CLAUDE.md, README.md, docs/, .claude/, .gitea/, .husky/, .vscode/, and the
docker-compose files stay at the repo root, since they'll apply to both the
app and the future backend.

No application code needed changes (all its internal paths are relative to
its own tree). Adjusted what referenced the old root from outside:
- .husky/pre-commit: cd into "Max Avatar" before lint-staged
- .gitea/workflows/*.yml: working-directory + cache-dependency-path +
  artifact paths + SonarQube projectBaseDir
- docker-compose.yml: build context -> ./Max Avatar
- Max Avatar/Dockerfile: node:20-alpine -> node:24-alpine (same node:sqlite
  issue already fixed elsewhere, never applied here before)
- .vscode/launch.json, README.md: updated paths/instructions

Verified from Max Avatar/ after the move: npm ci, typecheck, lint,
test:coverage (473/473, same coverage numbers), build, and dev all work
unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:15:30 +01:00

237 lines
8.4 KiB
TypeScript

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()
})
})