import test from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import {runInNewContext} from 'node:vm'; test('alleen een systeemmanager kan een geldig actief weergaveprofiel projecteren',async()=>{ const source=await readFile('public/js/permissions.js','utf8'); const context={currentUser:{role:'super',extraRoles:[]}}; runInNewContext(source+';globalThis.api={setActiveViewRole,activeRole,activeRoles,can,VIEW_ROLES}',context); const api=context.api; assert.deepEqual(Array.from(api.VIEW_ROLES),['super','admin','teacher','parent','pupil']); api.setActiveViewRole('parent'); assert.equal(api.activeRole(),'parent'); assert.equal(api.can('curriculum.view'),true); assert.equal(api.can('admin.access'),false); api.setActiveViewRole('pupil'); assert.equal(api.activeRole(),'pupil'); assert.equal(api.can('curriculum.view'),false); api.setActiveViewRole('onbekend'); assert.equal(api.activeRole(),'super'); context.currentUser={role:'teacher',extraRoles:[]}; api.setActiveViewRole('parent'); assert.equal(api.activeRole(),'teacher'); }); test('Weergave bevat de vijf rollen en laadt de veilige voorbeeldmodule vóór de appstart',async()=>{ const [html,preview,core,css,version]=await Promise.all([ readFile('public/index.html','utf8'), readFile('public/js/role-preview.js','utf8'), readFile('public/js/core.js','utf8'), readFile('public/css/teach.css','utf8'), readFile('VERSION','utf8') ]); for(const role of ['super','admin','teacher','parent','pupil'])assert.match(html,new RegExp('data-role="'+role+'"')); assert.match(html,/id="superViewRole" hidden/); assert.ok(html.indexOf('js/role-preview.js'){ const [client,server,settings,admin,explorer,pupil]=await Promise.all([ readFile('public/js/permissions.js','utf8'), readFile('src/permissions.js','utf8'), readFile('public/js/settings.js','utf8'), readFile('public/js/admin.js','utf8'), readFile('public/js/explorer.js','utf8'), readFile('public/js/pupil.js','utf8') ]); assert.match(client,/function activeRoles\(\)/); assert.doesNotMatch(server,/VIEW_AS_ROLE|activeRole/); assert.match(settings,/T\("vwRole"\)/); assert.match(admin,/activeRoles\(\)\.flatMap/); assert.match(admin,/show:\(\)=>activeRole\(\)==="super"/); assert.match(explorer,/activeRole\(\) === "pupil"/); assert.match(pupil,/async function renderPupilWidgets\(widgets, mode, preview=false\)/); assert.match(pupil,/if\(!preview\)await Promise\.all/); });