chore(cleanup): remove old SQLite coach pipeline
The entire local-SQLite Coach teaching pipeline (objective/level/plan/module agents, course-build stepper, written-exercise and drawing windows, review scheduler, screen/camera vision capture for blockage detection, and their renderer views) is retired: it will be replaced by a brand new 7-agent pipeline living server-side in Max API/Postgres, built in a later step. Removes src/main/coach/, the coach and vision skill definitions, the coach renderer views and CourseBuildStepper, drawRoughShapes, useCameraCapture, the camera-frame IPC bridge, and the shared coach/courseBuild/drawing types. Strips the corresponding pipeline guard-rails, system-prompt instructions and IPC handlers from openrouter.ts/index.ts/preload. Drops the now-unused mermaid/roughjs dependencies. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,12 +26,10 @@ vi.mock('../../../src/renderer/src/voice/useVoiceAssistant', () => ({ useVoiceAs
|
||||
vi.mock('../../../src/renderer/src/voice/useProactiveSpeech', () => ({
|
||||
useProactiveSpeech: vi.fn()
|
||||
}))
|
||||
vi.mock('../../../src/renderer/src/voice/useCameraCapture', () => ({ useCameraCapture: vi.fn() }))
|
||||
vi.mock('../../../src/renderer/src/voice/useMeetingRecorder', () => ({
|
||||
useMeetingRecorder: vi.fn()
|
||||
}))
|
||||
|
||||
let onCourseBuildStepCb: ((state: unknown) => void) | undefined
|
||||
let onUpdateAvailableCb: (() => void) | undefined
|
||||
let onUpdateReadyCb: (() => void) | undefined
|
||||
const sendDroppedFiles = vi.fn()
|
||||
@@ -46,10 +44,6 @@ const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string
|
||||
|
||||
function setupWindowApi(): void {
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
onCourseBuildStep: vi.fn((cb: (s: unknown) => void) => {
|
||||
onCourseBuildStepCb = cb
|
||||
return () => {}
|
||||
}),
|
||||
onUpdateAvailable: vi.fn((cb: () => void) => {
|
||||
onUpdateAvailableCb = cb
|
||||
return () => {}
|
||||
@@ -109,17 +103,6 @@ describe('<App />', () => {
|
||||
expect(screen.queryByText(/Erreur reseau/)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display the course build stepper once a state arrives', () => {
|
||||
render(<App />)
|
||||
act(() =>
|
||||
onCourseBuildStepCb?.({
|
||||
subject: 'algebre',
|
||||
steps: [{ key: 'recherche', label: 'Recherche', status: 'done' }]
|
||||
})
|
||||
)
|
||||
expect(screen.getByText(/algebre/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display the update banner when an update is available, then ready', () => {
|
||||
render(<App />)
|
||||
act(() => onUpdateAvailableCb?.())
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, act } from '@testing-library/react'
|
||||
|
||||
const drawShape = vi.fn()
|
||||
vi.mock('../../../src/renderer/src/components/drawRoughShapes', () => ({ drawShape }))
|
||||
|
||||
const roughCanvas = vi.fn(() => ({}))
|
||||
vi.mock('roughjs', () => ({ default: { canvas: roughCanvas } }))
|
||||
|
||||
const mermaidRender = vi.fn(async () => ({ svg: '<svg></svg>' }))
|
||||
const mermaidInitialize = vi.fn()
|
||||
vi.mock('mermaid', () => ({
|
||||
default: { initialize: mermaidInitialize, render: mermaidRender }
|
||||
}))
|
||||
|
||||
interface InitDrawingPayload {
|
||||
title: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
interface RevealShapePayload {
|
||||
requestId: string
|
||||
shape: { type: string }
|
||||
audio: ArrayBuffer | null
|
||||
}
|
||||
interface RenderMermaidPayload {
|
||||
requestId: string
|
||||
title: string
|
||||
mermaidCode: string
|
||||
}
|
||||
interface PlayCaptionPayload {
|
||||
requestId: string
|
||||
audio: ArrayBuffer
|
||||
}
|
||||
|
||||
const listeners: {
|
||||
onInitDrawing?: (payload: InitDrawingPayload) => void
|
||||
onRevealShape?: (payload: RevealShapePayload) => void
|
||||
onRenderMermaid?: (payload: RenderMermaidPayload) => void
|
||||
onPlayCaption?: (payload: PlayCaptionPayload) => void
|
||||
} = {}
|
||||
|
||||
function setupWindowApi(): void {
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
onInitDrawing: vi.fn((cb: (payload: InitDrawingPayload) => void) => {
|
||||
listeners.onInitDrawing = cb
|
||||
return () => {}
|
||||
}),
|
||||
onRevealShape: vi.fn((cb: (payload: RevealShapePayload) => void) => {
|
||||
listeners.onRevealShape = cb
|
||||
return () => {}
|
||||
}),
|
||||
onRenderMermaid: vi.fn((cb: (payload: RenderMermaidPayload) => void) => {
|
||||
listeners.onRenderMermaid = cb
|
||||
return () => {}
|
||||
}),
|
||||
onPlayCaption: vi.fn((cb: (payload: PlayCaptionPayload) => void) => {
|
||||
listeners.onPlayCaption = cb
|
||||
return () => {}
|
||||
}),
|
||||
acknowledgeShapeReveal: vi.fn(),
|
||||
acknowledgeMermaidRendered: vi.fn(),
|
||||
acknowledgeCaptionDone: vi.fn()
|
||||
}
|
||||
}
|
||||
|
||||
const { default: CoachDrawingView } =
|
||||
await import('../../../src/renderer/src/components/CoachDrawingView')
|
||||
|
||||
describe('<CoachDrawingView />', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
setupWindowApi()
|
||||
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(
|
||||
{} as CanvasRenderingContext2D
|
||||
)
|
||||
})
|
||||
|
||||
it('should show a waiting message before any drawing is initialized', () => {
|
||||
render(<CoachDrawingView />)
|
||||
expect(screen.getByText(/En attente/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display the title once a drawing is initialized', () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() => listeners.onInitDrawing?.({ title: 'Mon dessin', width: 700, height: 500 }))
|
||||
expect(screen.getByText('Mon dessin')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should draw a revealed shape and acknowledge it when there is no audio', () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() => listeners.onInitDrawing?.({ title: 'Mon dessin', width: 700, height: 500 }))
|
||||
const api = (window as unknown as { api: { acknowledgeShapeReveal: ReturnType<typeof vi.fn> } })
|
||||
.api
|
||||
act(() =>
|
||||
listeners.onRevealShape?.({ requestId: 'r1', shape: { type: 'circle' }, audio: null })
|
||||
)
|
||||
expect(drawShape).toHaveBeenCalled()
|
||||
expect(api.acknowledgeShapeReveal).toHaveBeenCalledWith('r1')
|
||||
})
|
||||
|
||||
it('should switch to mermaid mode and render the diagram on success, waiting for the container to mount', async () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() =>
|
||||
listeners.onRenderMermaid?.({
|
||||
requestId: 'r2',
|
||||
title: 'Cycle de l-eau',
|
||||
mermaidCode: 'graph LR; A --> B'
|
||||
})
|
||||
)
|
||||
expect(screen.getByText('Cycle de l-eau')).toBeInTheDocument()
|
||||
const api = (
|
||||
window as unknown as { api: { acknowledgeMermaidRendered: ReturnType<typeof vi.fn> } }
|
||||
).api
|
||||
await waitFor(() => expect(api.acknowledgeMermaidRendered).toHaveBeenCalledWith('r2', true))
|
||||
})
|
||||
|
||||
it('should report a mermaid render failure', async () => {
|
||||
mermaidRender.mockRejectedValueOnce(new Error('syntaxe invalide'))
|
||||
render(<CoachDrawingView />)
|
||||
act(() =>
|
||||
listeners.onRenderMermaid?.({ requestId: 'r3', title: 'Echec', mermaidCode: 'invalide' })
|
||||
)
|
||||
const api = (
|
||||
window as unknown as { api: { acknowledgeMermaidRendered: ReturnType<typeof vi.fn> } }
|
||||
).api
|
||||
await waitFor(() =>
|
||||
expect(api.acknowledgeMermaidRendered).toHaveBeenCalledWith('r3', false, 'syntaxe invalide')
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,111 +0,0 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -1,236 +0,0 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -1,32 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import CourseBuildStepper from '../../../src/renderer/src/components/CourseBuildStepper'
|
||||
import type { CourseBuildState } from '../../../src/shared/courseBuild'
|
||||
|
||||
const STATE: CourseBuildState = {
|
||||
subject: 'algebre',
|
||||
steps: [
|
||||
{ key: 'recherche', label: 'Recherche approfondie', status: 'done', detail: '5 source(s)' },
|
||||
{ key: 'plan', label: 'Objectif et plan de modules', status: 'active' },
|
||||
{ key: 'redaction', label: 'Redaction des modules', status: 'pending' }
|
||||
]
|
||||
}
|
||||
|
||||
describe('<CourseBuildStepper />', () => {
|
||||
it('should display the subject name', () => {
|
||||
render(<CourseBuildStepper state={STATE} />)
|
||||
expect(screen.getByText(/algebre/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display every step label', () => {
|
||||
render(<CourseBuildStepper state={STATE} />)
|
||||
expect(screen.getByText('Recherche approfondie')).toBeInTheDocument()
|
||||
expect(screen.getByText('Objectif et plan de modules')).toBeInTheDocument()
|
||||
expect(screen.getByText('Redaction des modules')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display the detail text only for steps that have one', () => {
|
||||
render(<CourseBuildStepper state={STATE} />)
|
||||
expect(screen.getByText('5 source(s)')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,174 +0,0 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import {
|
||||
boxesOverlap,
|
||||
findFreeLabelPosition,
|
||||
drawArrowHead,
|
||||
drawShape,
|
||||
type LabelBox
|
||||
} from '../../../src/renderer/src/components/drawRoughShapes'
|
||||
import type { RoughCanvas } from 'roughjs/bin/canvas'
|
||||
|
||||
function fakeCtx(): {
|
||||
ctx: CanvasRenderingContext2D
|
||||
fillText: ReturnType<typeof vi.fn>
|
||||
beginPath: ReturnType<typeof vi.fn>
|
||||
fill: ReturnType<typeof vi.fn>
|
||||
} {
|
||||
const fillText = vi.fn()
|
||||
const beginPath = vi.fn()
|
||||
const fill = vi.fn()
|
||||
const ctx = {
|
||||
measureText: vi.fn(() => ({ width: 40 })),
|
||||
save: vi.fn(),
|
||||
restore: vi.fn(),
|
||||
beginPath,
|
||||
moveTo: vi.fn(),
|
||||
lineTo: vi.fn(),
|
||||
closePath: vi.fn(),
|
||||
fill,
|
||||
fillText,
|
||||
fillStyle: '',
|
||||
font: ''
|
||||
} as unknown as CanvasRenderingContext2D
|
||||
return { ctx, fillText, beginPath, fill }
|
||||
}
|
||||
|
||||
function fakeRoughCanvas(): {
|
||||
rc: RoughCanvas
|
||||
rectangle: ReturnType<typeof vi.fn>
|
||||
circle: ReturnType<typeof vi.fn>
|
||||
line: ReturnType<typeof vi.fn>
|
||||
curve: ReturnType<typeof vi.fn>
|
||||
arc: ReturnType<typeof vi.fn>
|
||||
} {
|
||||
const rectangle = vi.fn()
|
||||
const circle = vi.fn()
|
||||
const line = vi.fn()
|
||||
const curve = vi.fn()
|
||||
const arc = vi.fn()
|
||||
const rc = { rectangle, circle, line, curve, arc } as unknown as RoughCanvas
|
||||
return { rc, rectangle, circle, line, curve, arc }
|
||||
}
|
||||
|
||||
describe('boxesOverlap()', () => {
|
||||
it('should detect overlapping boxes', () => {
|
||||
const a: LabelBox = { x: 0, y: 0, width: 10, height: 10 }
|
||||
const b: LabelBox = { x: 5, y: 5, width: 10, height: 10 }
|
||||
expect(boxesOverlap(a, b)).toBe(true)
|
||||
})
|
||||
|
||||
it('should detect non-overlapping boxes', () => {
|
||||
const a: LabelBox = { x: 0, y: 0, width: 10, height: 10 }
|
||||
const b: LabelBox = { x: 100, y: 100, width: 10, height: 10 }
|
||||
expect(boxesOverlap(a, b)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('findFreeLabelPosition()', () => {
|
||||
it('should return the starting position when nothing is placed yet', () => {
|
||||
const { ctx } = fakeCtx()
|
||||
const box = findFreeLabelPosition(ctx, 'Label', 10, 30, [])
|
||||
expect(box).toEqual({ x: 10, y: 14, width: 40, height: 16 })
|
||||
})
|
||||
|
||||
it('should shift downward to avoid an already-placed overlapping box', () => {
|
||||
const { ctx } = fakeCtx()
|
||||
const placed: LabelBox[] = [{ x: 10, y: 14, width: 40, height: 16 }]
|
||||
const box = findFreeLabelPosition(ctx, 'Label', 10, 30, placed)
|
||||
expect(box.y).toBeGreaterThan(14)
|
||||
})
|
||||
|
||||
it('should fall back to the last attempted position after 20 attempts if always overlapping', () => {
|
||||
const { ctx } = fakeCtx()
|
||||
const placed: LabelBox[] = Array.from({ length: 25 }, (_, i) => ({
|
||||
x: 10,
|
||||
y: 14 + i * 16,
|
||||
width: 40,
|
||||
height: 16
|
||||
}))
|
||||
const box = findFreeLabelPosition(ctx, 'Label', 10, 30, placed)
|
||||
expect(box).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('drawArrowHead()', () => {
|
||||
it('should draw a filled triangle at the arrow tip', () => {
|
||||
const { ctx, beginPath, fill } = fakeCtx()
|
||||
drawArrowHead(ctx, 0, 0, 10, 10, '#000')
|
||||
expect(beginPath).toHaveBeenCalled()
|
||||
expect(fill).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('drawShape()', () => {
|
||||
it('should draw a rectangle', () => {
|
||||
const { rc, rectangle } = fakeRoughCanvas()
|
||||
const { ctx } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'rect', x: 1, y: 2, width: 10, height: 20 }, [])
|
||||
expect(rectangle).toHaveBeenCalledWith(1, 2, 10, 20, expect.anything())
|
||||
})
|
||||
|
||||
it('should draw a circle', () => {
|
||||
const { rc, circle } = fakeRoughCanvas()
|
||||
const { ctx } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'circle', x: 1, y: 2, radius: 5 }, [])
|
||||
expect(circle).toHaveBeenCalledWith(1, 2, 10, expect.anything())
|
||||
})
|
||||
|
||||
it('should draw a line and position its label at the segment midpoint', () => {
|
||||
const { rc, line } = fakeRoughCanvas()
|
||||
const { ctx, fillText } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'line', x: 0, y: 0, x2: 10, y2: 0, label: 'AB' }, [])
|
||||
expect(line).toHaveBeenCalledWith(0, 0, 10, 0, expect.anything())
|
||||
expect(fillText).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should draw an arrow with an arrowhead', () => {
|
||||
const { rc, line } = fakeRoughCanvas()
|
||||
const { ctx, fill } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'arrow', x: 0, y: 0, x2: 10, y2: 10 }, [])
|
||||
expect(line).toHaveBeenCalled()
|
||||
expect(fill).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should draw a stroke curve only when at least 2 points are given', () => {
|
||||
const { rc, curve } = fakeRoughCanvas()
|
||||
const { ctx } = fakeCtx()
|
||||
drawShape(
|
||||
rc,
|
||||
ctx,
|
||||
{
|
||||
type: 'stroke',
|
||||
points: [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 1 }
|
||||
]
|
||||
},
|
||||
[]
|
||||
)
|
||||
expect(curve).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should not draw a stroke with fewer than 2 points', () => {
|
||||
const { rc, curve } = fakeRoughCanvas()
|
||||
const { ctx } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'stroke', points: [{ x: 0, y: 0 }] }, [])
|
||||
expect(curve).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should draw an arc', () => {
|
||||
const { rc, arc } = fakeRoughCanvas()
|
||||
const { ctx } = fakeCtx()
|
||||
drawShape(rc, ctx, { type: 'arc', x: 0, y: 0, radius: 10, startAngle: 0, endAngle: 90 }, [])
|
||||
expect(arc).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should draw text content directly and record its label box', () => {
|
||||
const { rc } = fakeRoughCanvas()
|
||||
const { ctx, fillText } = fakeCtx()
|
||||
const placed: LabelBox[] = []
|
||||
drawShape(rc, ctx, { type: 'text', x: 0, y: 0, content: 'Bonjour' }, placed)
|
||||
expect(fillText).toHaveBeenCalledWith('Bonjour', 0, 0)
|
||||
expect(placed.length).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -1,51 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
|
||||
let onCaptureCallback: ((requestId: string) => void) | undefined
|
||||
const sendCameraFrameResult = vi.fn()
|
||||
const onCaptureCameraFrame = vi.fn((cb: (requestId: string) => void) => {
|
||||
onCaptureCallback = cb
|
||||
return () => {}
|
||||
})
|
||||
|
||||
const stopTrack = vi.fn()
|
||||
const getUserMedia = vi.fn(async () => ({
|
||||
getTracks: () => [{ stop: stopTrack }]
|
||||
}))
|
||||
|
||||
const { useCameraCapture } = await import('../../../src/renderer/src/voice/useCameraCapture')
|
||||
|
||||
describe('useCameraCapture()', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
onCaptureCameraFrame,
|
||||
sendCameraFrameResult
|
||||
}
|
||||
Object.defineProperty(navigator, 'mediaDevices', {
|
||||
value: { getUserMedia },
|
||||
configurable: true
|
||||
})
|
||||
vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()
|
||||
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({
|
||||
drawImage: vi.fn()
|
||||
} as unknown as CanvasRenderingContext2D)
|
||||
HTMLCanvasElement.prototype.toDataURL = vi.fn(() => 'data:image/png;base64,abc')
|
||||
})
|
||||
|
||||
it('should capture a frame and send it back on request', async () => {
|
||||
renderHook(() => useCameraCapture())
|
||||
onCaptureCallback?.('req-1')
|
||||
await vi.waitFor(() => expect(sendCameraFrameResult).toHaveBeenCalled())
|
||||
expect(sendCameraFrameResult).toHaveBeenCalledWith('req-1', 'data:image/png;base64,abc')
|
||||
expect(stopTrack).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should send null when the camera is unavailable', async () => {
|
||||
getUserMedia.mockRejectedValueOnce(new Error('no camera'))
|
||||
renderHook(() => useCameraCapture())
|
||||
onCaptureCallback?.('req-2')
|
||||
await vi.waitFor(() => expect(sendCameraFrameResult).toHaveBeenCalled())
|
||||
expect(sendCameraFrameResult).toHaveBeenCalledWith('req-2', null)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user