import { describe, it, expect } from 'vitest' import { validateModuleContent, missingContentSections } from '../../src/main/coach/coachStore' function buildValidContent(): string { return [ 'Accroche', 'Un vendeur doit calculer rapidement combien de tissu acheter pour couvrir un mur triangulaire. '.repeat( 16 ), 'Developpement theorique', 'Idee centrale, analogie, definition formelle, exemple resolu et contre-exemple. '.repeat(35), 'Phase guidee', 'ETAPE 1 : identifier les donnees. ETAPE 2 : appliquer la formule. ETAPE 3 : verifier le resultat.', 'Exercices progressifs', 'EXERCICE 1 facile. EXERCICE 2 facile. EXERCICE 3 moyen. EXERCICE 4 moyen. EXERCICE 5 difficile. EXERCICE 6 difficile.', 'Exercice de debogage', "Trouve l'erreur dans ce calcul errone et corrige-la.", 'Synthese', 'Resume final avec question de meta-cognition et test Feynman. '.repeat(15) ].join('\n\n') } describe('missingContentSections()', () => { it('should return every required section when content is empty', () => { const missing = missingContentSections('') expect(missing).toContain('Accroche') expect(missing).toContain('Synthese') expect(missing.length).toBe(6) }) it('should return no missing section when all section headers are present', () => { expect(missingContentSections(buildValidContent())).toEqual([]) }) }) describe('validateModuleContent()', () => { it('should accept well-structured content meeting all requirements', () => { expect(validateModuleContent(buildValidContent())).toEqual([]) }) it('should reject content with missing sections', () => { const violations = validateModuleContent('Accroche\nTrop court.') expect(violations.length).toBeGreaterThan(0) expect(violations[0]).toMatch(/Sections manquantes/) }) it('should accept accented "ETAPE"/"EXERCICE" headers (regression: accent-insensitive match)', () => { const content = buildValidContent().replace('ETAPE', 'ÉTAPE').replace('EXERCICE', 'ÉXERCICE') expect(validateModuleContent(content)).toEqual([]) }) it('should reject a "Phase guidee" section with fewer than 3 numbered steps', () => { const content = buildValidContent().replace( 'ETAPE 1 : identifier les donnees. ETAPE 2 : appliquer la formule. ETAPE 3 : verifier le resultat.', 'ETAPE 1 : identifier les donnees.' ) const violations = validateModuleContent(content) expect(violations.some((v) => /Phase guidee/.test(v))).toBe(true) }) it('should reject an "Exercices progressifs" section with fewer than 6 numbered exercises', () => { const content = buildValidContent().replace( 'EXERCICE 1 facile. EXERCICE 2 facile. EXERCICE 3 moyen. EXERCICE 4 moyen. EXERCICE 5 difficile. EXERCICE 6 difficile.', 'EXERCICE 1 facile. EXERCICE 2 moyen.' ) const violations = validateModuleContent(content) expect(violations.some((v) => /Exercices progressifs/.test(v))).toBe(true) }) it('should reject an "Exercice de debogage" section that never mentions an error', () => { const content = buildValidContent().replace( "Trouve l'erreur dans ce calcul errone et corrige-la.", 'Resous ce calcul.' ) const violations = validateModuleContent(content) expect(violations.some((v) => /debogage/.test(v))).toBe(true) }) it('should reject a section shorter than its required minimum word count', () => { const shortAccroche = 'Un vendeur doit calculer rapidement combien de tissu acheter pour couvrir un mur triangulaire. '.repeat( 16 ) const content = buildValidContent().replace(shortAccroche, 'Phrase courte.') const violations = validateModuleContent(content) expect(violations.some((v) => /Accroche.*trop courte/.test(v))).toBe(true) }) })