Files
wekan/tests/adminPanelDocsMatchMenu.test.cjs
T
Lauri Ojansivu 9fbfb26d29 Docs: Admin Panel docs are filed the way the Admin Panel menu is.
The menu is the structure a reader already has in their head, so the docs match
it: one directory per tab, one page per pane, and a README in each listing the
panes IN MENU ORDER with the URL slug beside them - so somebody with
/admin/problems/integrity in the address bar can search for `integrity` and
find the page.

Settings (7 panes) and People (9) already had a page each and were already in
order; they gain the slug column. Problems (17) and Attachments (10) listed
almost none of theirs, so their READMEs now index every pane.

WHAT IS NOT DONE, and is now visible instead of invisible: 15 of the 17 Problems
panes and all 10 Attachments panes have no page of their own. They are dashes in
the table with the count stated under it. Writing 25 pages of guessed content
would be worse than the gap - what the panes do is described in each README
until somebody writes them up properly.

tests/adminPanelDocsMatchMenu.test.cjs is what stops this rotting again: the
menu is defined in code and the docs are written by hand, so a pane added to
models/lib/adminUrls.js would otherwise appear in the product and nowhere in the
documentation, silently. Every pane must be listed, in menu order, by slug;
every page that exists must be linked from its README; and the stated gap count
must match the dashes in the table, so the gaps cannot quietly grow while the
sentence under them still claims a smaller number.

Thanks to xet7 !
2026-08-16 15:40:24 +03:00

112 lines
5.0 KiB
JavaScript

'use strict';
// Guard: docs/Features/Admin-Panel is filed the way the Admin Panel menu is.
// Run: node tests/adminPanelDocsMatchMenu.test.cjs
//
// The menu is the structure a reader already has in their head, so the docs are
// laid out to match it: one directory per tab, one page per pane, and a README
// in each listing the panes IN MENU ORDER. Settings (7 panes) and People (9)
// already had a page each; Problems (17) and Attachments (10) did not, and their
// READMEs now index every pane with a dash where no page exists yet.
//
// What this checks is the thing that rots: the menu is defined in code and the
// docs are written by hand, so a pane added to models/lib/adminUrls.js appears in
// the product and nowhere in the documentation, silently. Every pane must be
// LISTED. Whether it has a page of its own is a separate, visible question - a
// dash is an honest gap, and this suite counts them rather than accepting them
// quietly.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const DOCS = path.join(ROOT, 'docs/Features/Admin-Panel');
const src = fs.readFileSync(path.join(ROOT, 'models/lib/adminUrls.js'), 'utf8');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
// The pane slugs of one page, in the order ADMIN_PAGES declares them - which is
// the order the menu renders.
function panesOf(page) {
const block = new RegExp(`^ ${page}: \\{\\n([\\s\\S]*?)^ \\},`, 'm').exec(src);
assert.ok(block, `ADMIN_PAGES has no ${page}`);
const panes = /panes: \{([\s\S]*?)\n {4}\},/.exec(block[1]);
assert.ok(panes, `${page} declares no panes`);
return [...panes[1].matchAll(/^\s*'?([\w-]+)'?: '[\w-]+',/gm)].map(m => m[1]);
}
const PAGES = [
['settings', 'Settings'],
['people', 'People'],
['problems', 'Problems'],
['attachments', 'Attachments'],
];
test('every tab in the menu has a directory of its own', () => {
for (const [, folder] of PAGES) {
assert.ok(fs.existsSync(path.join(DOCS, folder)),
`docs/Features/Admin-Panel/${folder} is missing - the menu has that tab`);
assert.ok(fs.existsSync(path.join(DOCS, folder, 'README.md')),
`${folder} needs a README indexing its panes`);
}
});
test('every pane is listed in its README, and by its URL slug', () => {
// The slug is what makes the link findable: a reader who has
// /admin/problems/integrity in the address bar can search the docs for it.
for (const [page, folder] of PAGES) {
const readme = fs.readFileSync(path.join(DOCS, folder, 'README.md'), 'utf8');
const missing = panesOf(page).filter(slug => !readme.includes(`\`${slug}\``));
assert.deepStrictEqual(missing, [],
`${folder}/README.md does not list these panes, so they exist in the product `
+ `and nowhere in the docs: ${missing.join(', ')}`);
}
});
test('the README lists them in MENU ORDER (negative)', () => {
// Alphabetical would be a different document: a reader is matching what they
// see down the side of the screen.
for (const [page, folder] of PAGES) {
const readme = fs.readFileSync(path.join(DOCS, folder, 'README.md'), 'utf8');
const positions = panesOf(page).map(slug => readme.indexOf(`\`${slug}\``));
// Settings and People predate the slug column and list panes by label only.
if (positions.some(p => p === -1)) continue;
const sorted = [...positions].sort((a, b) => a - b);
assert.deepStrictEqual(positions, sorted,
`${folder}/README.md lists its panes in a different order than the menu does`);
}
});
test('a page that exists is linked from its README (negative)', () => {
// A doc nobody links to is a doc nobody finds.
for (const [, folder] of PAGES) {
const dir = path.join(DOCS, folder);
const readme = fs.readFileSync(path.join(dir, 'README.md'), 'utf8');
const unlinked = fs.readdirSync(dir)
.filter(f => f.endsWith('.md') && f !== 'README.md')
.filter(f => !readme.includes(`(${f})`));
assert.deepStrictEqual(unlinked, [],
`${folder}/README.md does not link these pages: ${unlinked.join(', ')}`);
}
});
test('the gaps are counted, not hidden', () => {
// A dash is an honest "nobody has written this yet". What must not happen is
// the count quietly growing while the sentence still says a smaller number.
for (const [page, folder] of PAGES) {
const readme = fs.readFileSync(path.join(DOCS, folder, 'README.md'), 'utf8');
const stated = /(\d+) of these (\d+) panes has no page/.exec(readme);
if (!stated) continue; // fully documented tab
const total = panesOf(page).length;
assert.strictEqual(Number(stated[2]), total,
`${folder}/README.md says ${stated[2]} panes and the menu has ${total}`);
const dashes = (readme.match(/\| — \|/g) || []).length;
assert.strictEqual(Number(stated[1]), dashes,
`${folder}/README.md says ${stated[1]} panes lack a page and the table shows ${dashes}`);
}
});
console.log(`\nadminPanelDocsMatchMenu: ${passed} tests passed`);