teach/test/role-preview.test.js
Ramon 629329894d
All checks were successful
dev - build & deploy naar test / build-and-deploy (push) Successful in 53s
feat: laat systeemmanager leerlingwidgets toevoegen (v0.4.40-beta)
2026-07-20 16:06:33 +02:00

71 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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')<html.indexOf('js/app.js'));
assert.match(preview,/currentUser\.role==="super"/);
assert.match(preview,/renderParentView\(\[\]\)/);
assert.match(preview,/renderPupilWidgets\(snapshot\.widgets\|\|\[\],"kijken",true\)/);
assert.match(preview,/querySelectorAll\("button,input,select,textarea"\)/);
assert.match(preview,/pupilAllowedDefs\(\)\.forEach/);
assert.match(preview,/pupilAllowedDefs\(\)\.includes\(def\)/);
assert.match(preview,/setActiveViewRole\("super"\)[\s\S]*?makeWidget\(def\)[\s\S]*?await doSave\(\)/);
assert.match(preview,/role-preview-add-widget/);
assert.doesNotMatch(preview,/currentUser\.role\s*=(?!=)/);
assert.doesNotMatch(preview,/api\(/);
assert.match(css,/body\.role-preview-pupil #pupilView \.widget-body\{pointer-events:none/);
for(const key of ['vwRole','vwRoleSystem','vwRoleAdmin','vwRoleTeacher','vwRoleParent','vwRolePupil','vwRoleNote','vwPreviewReset','vwPupilAddWidget','vwPupilChooseWidget','vwPupilAddWidgetNote']){
assert.equal((core.match(new RegExp(key+':','g'))||[]).length,2,key);
}
assert.ok(core.includes('const VERSION = "'+version.trim()+'"'));
});
test('voorbeeldrol begrenst clientmenus maar verandert serverpermissies niet',async()=>{
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/);
});