Files
wekan/tests/templateRegistration.test.cjs
T
Lauri Ojansivu 0461de062f Board: the second header bar is gone. It was the last one.
Three things, as asked.

NO DUPLICATE BOARD NAME. The second bar drew the board's title in an `h1` of its
own, under the same name in the bar above it. The first bar has said it since
the first step of this work; the h1 is gone.

THE PENCIL IS BESIDE THE NAME. Renaming a board belongs next to the board's
name, not in a bar of its own, so `boardEditTitleButton` renders immediately
right of the title in the first bar. Board admins only, as before.

EVERYTHING ELSE IS AN ICON, LEFT OF THE BELL. Visibility, watch, star, sort,
the board's rule buttons, filter, search, dependencies and Multi-Selection, each
named by a tooltip and none carrying a visible label. The bar is one row shared
with the logo, the starred boards, the view menu, the bell and the user menu;
ten labelled buttons do not fit at any width.

The desktop/mobile duplication went with it. The old bar wrote the whole set out
TWICE - `unless isMiniScreen` and `if isMiniScreen` - because a row of labelled
buttons does not fit on a phone. Icons do, so one copy serves both, and the two
switches that had to be kept in step are gone rather than kept in step.

headerBarControls.jade is deleted. It held one Search button and one
Multi-Selection button, written for this bar and All Boards'; both bars are gone
now, so a template shared by nobody was indirection rather than sharing.

Every route reference goes with the bar: config/router.js names no headerBar at
all any more.

Six guards followed, and four of them existed only to measure this bar: the
title-plus-buttons row that a long board title split across two lines, the
wrapper that fixed it, the phone layout, and the hamburger that shared the first
row with the title. All of that was one problem, and the problem is gone with
the row. Each says so where it used to measure it, rather than being deleted.

Thanks to xet7 !
2026-07-31 13:57:06 +03:00

116 lines
5.2 KiB
JavaScript

'use strict';
// A .jade file is not picked up by being on disk. Every one of them has to be
// imported from a `client/features/*.js` list, and a template that is not
// imported is "No such template: <name>" the moment something renders it -
// which is how `headerBarControls.jade` shipped: the file existed, both header
// bars included `+headerSearchButton`, and All Boards threw on render.
//
// Two things are checked, both of which have gone wrong:
// * every .jade under client/components is imported somewhere;
// * every `+template` used in one of them resolves to a template that some
// imported .jade actually defines.
//
// Run: node tests/templateRegistration.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
function walk(dir, ext, out = []) {
for (const entry of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
const rel = `${dir}/${entry.name}`;
if (entry.isDirectory()) walk(rel, ext, out);
else if (entry.name.endsWith(ext)) out.push(rel);
}
return out;
}
const jadeFiles = walk('client/components', '.jade');
// The import lists: client/features/*.js plus the few top-level client files.
const importSources = [
...walk('client/features', '.js'),
...fs.readdirSync(path.join(ROOT, 'client'))
.filter(f => f.endsWith('.js'))
.map(f => `client/${f}`),
];
const allImports = importSources.map(read).join('\n');
let passed = 0;
const tests = [];
function test(name, fn) { tests.push([name, fn]); }
console.log('templateRegistration:');
test('every .jade under client/components is imported', () => {
const missing = jadeFiles.filter(f => !allImports.includes(`'/${f}'`));
assert.deepStrictEqual(missing, [],
`these compile to nothing and their templates do not exist at runtime: ${missing.join(', ')}`);
});
test('and every +template it includes is defined by one of them', () => {
// Only templates DEFINED in this repo's jade are resolvable this way; a
// `+something` that is not defined anywhere is the runtime error.
const defined = new Set();
for (const f of jadeFiles) {
for (const m of read(f).matchAll(/^\s*template\(name=["'](\w+)["']\)/gm)) defined.add(m[1]);
}
// Not from a .jade in this repo: `+Template.dynamic` is Blaze's own, and
// these three come from packages (useraccounts, wekan-markdown).
const external = new Set(['Template', 'atForm', 'markdown', 'mentions', 'fullcalendar']);
// A dangling include that is NOT this change's, recorded rather than hidden.
// `client/components/cards/subtasks.jade` includes `+subtaskDeleteDialog`,
// which no template defines - it would throw the moment it rendered. It never
// does: the branch is `if toggleDeleteDialog.get`, and that ReactiveVar is
// initialised to false in subtasks.js and never set to true by anything. So
// it is unreachable dead markup around a template that was never written,
// left here with its reason so whoever picks up subtask deletion sees it.
const KNOWN_DANGLING = new Set(['client/components/cards/subtasks.jade:8: +subtaskDeleteDialog']);
const unresolved = [];
for (const f of jadeFiles) {
read(f).split('\n').forEach((line, i) => {
// `+name` or `+name(args)`, at the start of a jade line.
const m = /^\s*\+([A-Za-z_$][\w$]*)/.exec(line);
if (!m || external.has(m[1]) || defined.has(m[1])) return;
const where = `${f}:${i + 1}: +${m[1]}`;
if (!KNOWN_DANGLING.has(where)) unresolved.push(where);
});
}
assert.deepStrictEqual(unresolved, [],
`no .jade in client/components defines these: ${unresolved.join(', ')}`);
// And the known one must still be exactly where it is said to be, so the
// exemption cannot quietly cover a NEW dangling include in that file.
for (const known of KNOWN_DANGLING) {
const [file, lineNo, what] = [known.split(':')[0], Number(known.split(':')[1]), known.split(': ')[1]];
const line = read(file).split('\n')[lineNo - 1];
assert.ok(line && line.trim().startsWith(what),
`the known dangling include moved: ${known} is now "${line && line.trim()}"`);
}
});
test('the shared header controls are gone, with the bars they were for', () => {
// headerBarControls.jade held one Search button and one Multi-Selection
// button, written for the board's second header bar and All Boards'. Both
// bars are gone: All Boards keeps those two as sidebar rows, and the board's
// are icons in the first header bar. A template shared by nobody is not
// shared, it is indirection.
assert.ok(!fs.existsSync(path.join(ROOT, 'client/components/boards/headerBarControls.jade')),
'the file must be gone');
assert.ok(!allImports.includes('headerBarControls'), 'and nothing may import it');
const boardJade = read('client/components/boards/boardHeader.jade');
assert.ok(/js-open-search-view/.test(boardJade), 'the board draws Search itself');
assert.ok(/js-multiselection-activate/.test(boardJade), 'and Multi-Selection');
});
for (const [name, fn] of tests) {
try { fn(); passed++; console.log(' ok -', name); }
catch (err) { console.error(` FAIL - ${name}\n ${err.message}`); process.exitCode = 1; }
}
console.log(`\ntemplateRegistration: ${passed} tests passed`);