This commit is contained in:
Alvin-Zilverstand committed 2026-11-09 15:19:44 +01:00
1 parent ae2c99d71a
commit 846054b7b9
25 files changed
+2513 -148

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { projects, processes, source, revision } from '../content.js';
test('Evidence mappings use real process IDs and complete translations', () => {
assert.equal(processes.length, 8);
const ids = new Set(processes.map(p => p.code));
assert.equal(ids.size, 8);
assert.equal(new Set(projects.map(p => p.id)).size, projects.length);
for (const p of projects) {
for (const key of ['kind', 'title', 'name', 'intro', 'context', 'implementation', 'decisions']) {
assert.equal(p[key].length, 2, `${p.id}.${key}`);
assert.ok(p[key].every(s => typeof s === 'string' && s.length > 0));
}
for (const e of p.evidence) {
assert.ok(e.codes.every(c => ids.has(c)), e.path);
assert.ok(e.label.length === 2 && e.label.every(Boolean));
const url = new URL(source(e.path, e.directory));
assert.equal(url.hostname, 'github.com');
assert.ok(url.pathname.includes(revision));
assert.equal(decodeURIComponent(url.pathname.split(`${revision}/`)[1]), e.path);
}
}
});
test('Collaboration gaps remain explicit rather than claiming unsupported evidence', () => {
for (const code of ['B1-K2-W1', 'B1-K2-W2', 'B1-K2-W3']) {
assert.ok(!projects.some(p => p.evidence.some(e => e.codes.includes(code))));
}
});
+43
View File
@@ -0,0 +1,43 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { compileContent, validateProjects } from '../scripts/content.mjs';
import { projects, processes } from '../content.js';
import { profile, source } from '../content.js';
import { readFile } from 'node:fs/promises';
import { runInNewContext } from 'node:vm';
test('content compiler preserves source data', async () => {
const result = await import(`data:text/javascript;base64,${Buffer.from(await compileContent()).toString('base64')}`);
assert.deepEqual(result.projects, projects);
});
test('deleting all projects or evidence is supported', () => {
assert.doesNotThrow(() => validateProjects([], processes));
assert.doesNotThrow(() => validateProjects(projects.map(p => ({ ...p, evidence: [] })), processes));
});
test('invalid routes, translations and mappings are rejected', () => {
for (const change of [{ id: '../invalid' }, { name: ['Only one language'] }, { codes: ['unknown'] }, { nodes: [] }]) {
assert.throws(() => validateProjects([{ ...projects[0], ...change }], processes));
}
assert.throws(() => validateProjects([projects[0], projects[0]], processes));
});
test('homepage renders after removing the featured project or all projects', async () => {
const code = (await readFile(new URL('../app.js', import.meta.url), 'utf8')).replace(/^import .*;\r?\n/, '');
for (const remaining of [projects.slice(1), []]) {
const elements = new Map();
const document = {
documentElement: {},
querySelector(selector) {
if (!elements.has(selector)) elements.set(selector, { innerHTML: '', addEventListener() {} });
return elements.get(selector);
},
querySelectorAll() { return []; },
};
runInNewContext(code, { profile, source, projects: remaining, processes, document, URLSearchParams, location: { search: '?lang=en', hash: '#home' }, window: { addEventListener() {} } });
const html = elements.get('main').innerHTML;
assert.ok(!html.includes('undefined'));
assert.ok(!html.includes('href="#project/warehouse"'));
if (remaining.length) assert.ok(html.includes(`href="#project/${remaining[0].id}"`));
else assert.ok(html.includes('No projects added yet.'));
}
});