import test from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import {runInNewContext} from 'node:vm'; async function progressionContext(){ const source=await readFile('public/js/learning-progressions.js','utf8'); const pure=source.slice(0,source.indexOf('(function registerOwnLearningLevelSettings')); const context={LANG:'nl'}; runInNewContext(pure+` ;globalThis.__profiles=LEARNING_YEAR_PROFILES; globalThis.__languageWordsForYear=languageWordsForYear; globalThis.__languageTaskRules=languageTaskRules; globalThis.__mathTaskRules=mathTaskRules; `,context); return context; } test('taal en rekenen hebben een compleet inhoudelijk profiel voor groep 1 tot en met 8',async()=>{ const {__profiles:profiles}=await progressionContext(); for(const subject of ['taal','rekenen']){ assert.equal(profiles[subject].length,9); for(let year=1;year<=8;year++){ const profile=profiles[subject][year]; assert.ok(profile.phase&&profile.title,subject+' groep '+year); assert.equal(profile.goals.length,3,subject+' groep '+year+' heeft drie concrete accenten'); } } }); test('alleen leerkracht en systeemmanager kunnen het leerjaar op hun eigen bord kiezen',async()=>{ const source=await readFile('public/js/learning-progressions.js','utf8'); const pure=source.slice(0,source.indexOf('(function registerOwnLearningLevelSettings')); const context={LANG:'nl',currentUser:{role:'teacher'}}; context.activeRole=()=>context.currentUser.role; runInNewContext(pure+';globalThis.__api={canConfigureBoardLearningLevel,boardLearningSelection}',context); const def={cat:'taal'}; assert.equal(context.__api.canConfigureBoardLearningLevel(def),true); assert.deepEqual(JSON.parse(JSON.stringify(context.__api.boardLearningSelection(def,null))),{yearGroup:4,level:2}); assert.deepEqual(JSON.parse(JSON.stringify(context.__api.boardLearningSelection(def,{}))),{yearGroup:4,level:2}); assert.deepEqual(JSON.parse(JSON.stringify(context.__api.boardLearningSelection(def,{yearGroup:7,level:3}))),{yearGroup:7,level:3}); context.currentUser={role:'super'}; assert.equal(context.__api.canConfigureBoardLearningLevel({cat:'rekenen'}),true); context.activeRole=()=>'teacher'; assert.equal(context.__api.canConfigureBoardLearningLevel(def),true); context.activeRole=()=>'pupil'; assert.equal(context.__api.canConfigureBoardLearningLevel(def),false); context.currentUser={role:'admin'}; context.activeRole=()=>context.currentUser.role; assert.equal(context.__api.canConfigureBoardLearningLevel(def),false); }); test('taalprofiel selecteert eenvoudiger woorden in de onderbouw en bouwt taaksteun af',async()=>{ const c=await progressionContext(); const words=[['kat','x'],['vis','x'],['pen','x'],['maan','x'],['boek','x'],['fiets','x'], ['brandweerauto','x'],['onderzoeker','x'],['verantwoordelijkheid','x']]; const early=JSON.parse(JSON.stringify(c.__languageWordsForYear(words,2,2))); const late=JSON.parse(JSON.stringify(c.__languageWordsForYear(words,8,2))); assert.ok(early.length!['brandweerauto','verantwoordelijkheid'].includes(word))); assert.equal(c.__languageTaskRules(2,2).flashSeconds,3); assert.equal(c.__languageTaskRules(7,2).flashSeconds,.5); assert.ok(c.__languageTaskRules(2,2).lives>c.__languageTaskRules(7,2).lives); }); test('rekenprofiel vergroot getalgebied, tafels en breuken per leerjaar',async()=>{ const c=await progressionContext(); assert.equal(c.__mathTaskRules(2,3).addSub,20); assert.equal(c.__mathTaskRules(3,1).timesTable,2); assert.equal(c.__mathTaskRules(3,3).timesTable,10); assert.equal(c.__mathTaskRules(4,3).addSub,100); assert.equal(c.__mathTaskRules(6,3).addSub,10000); assert.equal(c.__mathTaskRules(1,2).fractionDen,2); assert.equal(c.__mathTaskRules(8,3).fractionDen,12); assert.deepEqual(JSON.parse(JSON.stringify(c.__mathTaskRules(3,2).clockMinutes)),[0,15,30,45]); }); test('alle taal- en rekenwidgets ontvangen de centrale leerjaarstate en tonen het profiel',async()=>{ const [html,board,pupil,progressions,letters,flits,hak,ball,math,numberline,learning]=await Promise.all([ readFile('public/index.html','utf8'),readFile('public/js/board.js','utf8'), readFile('public/js/pupil.js','utf8'),readFile('public/js/learning-progressions.js','utf8'), ...['letters','flits','hak','ball','math','numberline','learning'].map(name=>readFile('public/js/widgets/'+name+'.js','utf8')), ]); assert.ok(html.indexOf('js/data.js')