teach/test/language-library.test.js
Ramon cb97dc2bb1
All checks were successful
dev - build & deploy naar test / build-and-deploy (push) Successful in 31s
feat: breid taalwidgets en plaatjesbibliotheek uit (v0.3.80-beta)
2026-07-16 16:27:38 +02:00

91 lines
4.5 KiB
JavaScript
Raw Permalink 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';
async function languageData(extra=''){
const source=await readFile('public/js/data.js','utf8');
const context={LANG:'nl',T:key=>key};
runInNewContext(source+`; ${extra}
globalThis.__language={
concepts:LANGUAGE_CONCEPTS,
themesNl:languageThemeList("nl"),
themesEn:languageThemeList("en"),
words:WORDS,
catalogNl:languagePictureCatalog("nl")
};`,context);
return JSON.parse(JSON.stringify(context.__language));
}
test('taalwidgets delen een ruime tweetalige woordenschat in acht duidelijke themas',async()=>{
const data=await languageData();
assert.ok(data.concepts.length>=140,'verwacht minimaal 140 vaste woordplaatjes');
assert.equal(data.themesNl.length,8);
assert.equal(data.themesEn.length,8);
assert.equal(new Set(data.concepts.map(item=>item.id)).size,data.concepts.length);
for(const concept of data.concepts){
assert.ok(concept.nl&&concept.en&&concept.pic,concept.id);
assert.ok(data.themesNl.some(theme=>theme.id===concept.theme),concept.theme);
}
for(const themes of [data.themesNl,data.themesEn]){
for(const theme of themes)assert.ok(theme.words.length>=10,theme.id);
assert.equal(themes.reduce((sum,theme)=>sum+theme.words.length,0),data.concepts.length);
}
});
test('alle oude startwoorden blijven staan en krijgen ook een bibliotheekplaatje',async()=>{
const data=await languageData();
const oldNl=['aap','vis','zon','kat','bal','ei','boom','huis','maan','boot','kip','muis','boek','ster','roos','vuur','fiets','taart','jas','bril','klok','peer','kaas','eend','hand','voet','neus','oog','oor','mond'];
const oldEn=['cat','dog','sun','egg','ball','fish','tree','moon','boat','star','book','cake','house','mouse','apple','train','fire','rose','bear','duck','frog','bee','cow','pig','hand','foot','nose','eye','ear','milk'];
assert.deepEqual(data.words.nl.map(([word])=>word),oldNl);
assert.deepEqual(data.words.en.map(([word])=>word),oldEn);
const names=new Set(data.catalogNl.images.map(image=>image.name));
for(const word of oldNl)assert.ok(names.has(word),word);
});
test('vaste en eigen woordplaatjes worden als herbruikbare catalogusitems aangeboden',async()=>{
const data=await languageData('GENERAL_EXTRA.nl=[["test","🧪"]]; THEMES.nl=[{name:"Boerderij",folder:"School",words:[["stal","🏚️"]]}];');
const builtins=data.catalogNl.images.filter(image=>image.builtin);
assert.equal(builtins.length,data.concepts.length);
assert.equal(data.catalogNl.themes.filter(theme=>theme.languageBuiltin).length,8);
for(const image of builtins){
assert.ok(image.id<0);
assert.ok(image.src.startsWith('data:image/svg+xml;charset=utf-8,'));
assert.ok(image.value&&image.themes.length===1);
assert.equal(image.canManage,false);
}
const testPic=data.catalogNl.images.find(image=>image.name==='test');
const stablePic=data.catalogNl.images.find(image=>image.name==='stal');
assert.equal(testPic.value,'🧪');
assert.equal(stablePic.value,'🏚️');
assert.equal(stablePic.folder,'Taal/Mijn themas/School/Boerderij');
});
test('alle vier taalspellen gebruiken themabronnen en kunnen de bibliotheek openen',async()=>{
const [data,catalog,picker,letters,css,catalogCss]=await Promise.all([
readFile('public/js/data.js','utf8'),
readFile('public/js/image-catalog.js','utf8'),
readFile('public/js/picker.js','utf8'),
readFile('public/js/widgets/letters.js','utf8'),
readFile('public/css/teach.css','utf8'),
readFile('public/css/image-catalog.css','utf8'),
]);
assert.match(data,/card\.startsWith\("b:"\)/);
assert.match(data,/builtinGroup\.label = "📚 "/);
for(const widget of ['letters','flits','hak','ball']){
const source=await readFile(`public/js/widgets/${widget}.js`,'utf8');
assert.match(source,/wordSourceList\(/,widget);
assert.match(source,/fillWordSourceSel\(/,widget);
}
assert.match(catalog,/refreshWordPictureCatalog/);
assert.match(catalog,/languagePictureCatalog\(LANG\)/);
assert.match(catalog,/ic-word-themes/);
assert.match(picker,/data-t="library"/);
assert.match(picker,/uploadImageToCatalog\(f,/);
assert.match(letters,/data-t="library"/);
assert.match(letters,/openImageCatalog\(\(src,image\)/);
assert.match(letters,/uploadImageToCatalog\(f,/);
assert.match(css,/\.ed-tabs\{[^}]*overflow-x:auto/);
assert.match(catalogCss,/\.ic-word-themes\{[^}]*overflow-x:auto/);
assert.match(catalogCss,/@media\(max-width:760px\)/);
});