102 lines
4.5 KiB
JavaScript
102 lines
4.5 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { classify, buildPath, compareEntries } from '../src/collections.js';
|
|
import openbureau from '../../examples/openbureau.config.js';
|
|
import kgva from '../../examples/kgva.config.js';
|
|
|
|
const ob = openbureau.collections;
|
|
const kg = kgva.collections;
|
|
|
|
// --- openbureau: must reproduce the original hard-coded classify() 1:1 ---
|
|
|
|
test('classify (openbureau): Beitrag = archiv/<section>/<slug>', () => {
|
|
assert.deepEqual(classify('archiv/software/stack.md', ob), { kind: 'beitrag', section: 'software' });
|
|
assert.deepEqual(classify('archiv/buerofuehrung/x.md', ob), { kind: 'beitrag', section: 'buerofuehrung' });
|
|
});
|
|
|
|
test('classify (openbureau): Library = library/<slug>, section konstant', () => {
|
|
assert.deepEqual(classify('library/stack.md', ob), { kind: 'biblio', section: 'library' });
|
|
});
|
|
|
|
test('classify (openbureau): _index.md = Rubrik, section = Elternordner|home', () => {
|
|
assert.deepEqual(classify('_index.md', ob), { kind: 'rubrik', section: 'home' });
|
|
assert.deepEqual(classify('software/_index.md', ob), { kind: 'rubrik', section: 'software' });
|
|
});
|
|
|
|
test('classify (openbureau): alles andere = Seite (fallback)', () => {
|
|
assert.deepEqual(classify('manifest.md', ob), { kind: 'seite', section: null });
|
|
// _index hat Vorrang vor jedem Pfad-Pattern (wie im Original)
|
|
assert.deepEqual(classify('library/_index.md', ob), { kind: 'rubrik', section: 'library' });
|
|
// archiv strikt drei-tief: tiefer faellt auf Seite (Original: len !== 3)
|
|
assert.deepEqual(classify('archiv/software/a/b.md', ob), { kind: 'seite', section: null });
|
|
});
|
|
|
|
test('buildPath (openbureau): aus Pfad-Pattern + Formulardaten', () => {
|
|
assert.equal(buildPath('beitrag', { section: 'software', slug: 'neu' }, ob), 'archiv/software/neu.md');
|
|
assert.equal(buildPath('biblio', { slug: 'stack' }, ob), 'library/stack.md');
|
|
assert.equal(buildPath('seite', { slug: 'impressum' }, ob), 'impressum.md');
|
|
assert.equal(buildPath('beitrag', { section: 'software', slug: '' }, ob), '');
|
|
});
|
|
|
|
test('compareEntries (openbureau): Reihenfolge Beitrag<Library<Seite<Rubrik', () => {
|
|
const items = [
|
|
{ kind: 'rubrik', date: null, title: 'R' },
|
|
{ kind: 'seite', date: null, title: 'S' },
|
|
{ kind: 'beitrag', date: '2024-01-01', title: 'B' },
|
|
{ kind: 'biblio', date: null, title: 'L' },
|
|
];
|
|
const sorted = [...items].sort(compareEntries(ob)).map((e) => e.kind);
|
|
assert.deepEqual(sorted, ['beitrag', 'biblio', 'seite', 'rubrik']);
|
|
});
|
|
|
|
test('compareEntries: gleiche kind -> Datum absteigend, dann Titel', () => {
|
|
const items = [
|
|
{ kind: 'beitrag', date: '2023-05-01', title: 'B' },
|
|
{ kind: 'beitrag', date: '2024-05-01', title: 'A' },
|
|
{ kind: 'beitrag', date: '2024-05-01', title: 'C' },
|
|
];
|
|
const sorted = [...items].sort(compareEntries(ob)).map((e) => e.title);
|
|
assert.deepEqual(sorted, ['A', 'C', 'B']);
|
|
});
|
|
|
|
// --- kgva: a different content model, same engine ---
|
|
|
|
test('classify (kgva): Portfolio / Fallback-Page / Index-Section', () => {
|
|
assert.deepEqual(classify('portfolio/projekt.md', kg), { kind: 'project', section: 'portfolio' });
|
|
assert.deepEqual(classify('ueber.md', kg), { kind: 'page', section: null });
|
|
assert.deepEqual(classify('_index.md', kg), { kind: 'section', section: 'home' });
|
|
assert.deepEqual(classify('arbeiten/_index.md', kg), { kind: 'section', section: 'arbeiten' });
|
|
});
|
|
|
|
test('buildPath (kgva)', () => {
|
|
assert.equal(buildPath('project', { slug: 'haus' }, kg), 'portfolio/haus.md');
|
|
assert.equal(buildPath('page', { slug: 'ueber' }, kg), 'ueber.md');
|
|
});
|
|
|
|
import { contentStats } from '../src/collections.js';
|
|
|
|
test('contentStats (openbureau): statKey-Zähler + entwuerfe = Beitrag-Entwürfe', () => {
|
|
const entries = [
|
|
{ kind: 'beitrag', draft: false },
|
|
{ kind: 'beitrag', draft: true },
|
|
{ kind: 'beitrag', draft: true },
|
|
{ kind: 'biblio', draft: true }, // Library-Entwurf zählt NICHT als entwuerfe
|
|
{ kind: 'seite', draft: false },
|
|
{ kind: 'rubrik', draft: false },
|
|
];
|
|
assert.deepEqual(contentStats(entries, ob), {
|
|
beitraege: 3, entwuerfe: 2, library: 1, rubriken: 1, seiten: 1,
|
|
});
|
|
});
|
|
|
|
test('contentStats (kgva): nur deklarierte statKeys, kein entwuerfe', () => {
|
|
const entries = [
|
|
{ kind: 'project', draft: true },
|
|
{ kind: 'project', draft: false },
|
|
{ kind: 'page', draft: false }, // page hat keinen statKey
|
|
{ kind: 'section', draft: false }, // section hat keinen statKey
|
|
];
|
|
assert.deepEqual(contentStats(entries, kg), { projects: 2 });
|
|
});
|