Files
wekan/tests/themeCategories.test.cjs
T
Lauri Ojansivu b7589737f5 File docs/Features the way the WeKan menus are.
A feature's guide now sits under the menu it is used from, read from the
templates rather than from where somebody once put it: Header-Bar,
All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar
(Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists,
Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several
menus (editor, history, theme, translations, email, troubleshooting) are in
General.

- Each area has a README mapping its menu entries to their guides and to the
  template or server module that implements them. Board-Header/README.md
  lists all 40 Board View entries with the template boardBody.jade renders;
  five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of
  their own yet and say so.
- Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all
  of them with their English labels.
- Pages keep their file names. Where a released changelog links an old path,
  a "# Moved" page stays there and points to the new one; test-menu.sh skips
  folders holding only those.
- Undo was filed under Login; it is General/Undo now.
- Every link in docs, code comments, scripts and tests follows the move;
  docsLinksResolve checks them all.

Tests that read a doc follow it to its new place. boardViewSettings now fails
when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or
names a template boardBody.jade does not render.

Thanks to xet7 !
2026-10-16 23:45:35 +03:00

94 lines
4.7 KiB
JavaScript

'use strict';
// Tests for the "Select Color" theme categories (models/lib/themeCategories.js):
// the category partition, the custom-color gating (flat=1, clear=2, dark/special=0),
// and the custom-colors validator — including negative cases. Also a source guard
// that the partition exactly covers config/const.js ALLOWED_BOARD_COLORS.
//
// Run: node tests/themeCategories.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const TC = require('../models/lib/themeCategories.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
test('categories partition into flat/clear/dark/special in order', () => {
assert.deepStrictEqual(TC.THEME_CATEGORY_ORDER, ['flat', 'clear', 'dark', 'special']);
// The colour slides. clearblue was alone until the five derived from the flat
// colours joined it - cleargreen from limegreen, clearorange from pumpkin,
// and so on - so the clear category covers the same colour families the flat
// one does. docs/Features/General/Theme/Change-Color.md
assert.deepStrictEqual(TC.colorsInCategory('clear'),
['clearblue', 'cleargreen', 'clearorange', 'clearpink', 'clearpurple', 'clearred']);
// Every one of them takes TWO custom colours, because a slide has two ends.
for (const slide of TC.colorsInCategory('clear')) {
assert.strictEqual(TC.categoryOf(slide), 'clear', `${slide} is a slide`);
assert.strictEqual(TC.customColorCount('clear'), 2);
assert.strictEqual(TC.isValidCustomColors(slide, ['#000000', '#ffffff']), true,
`${slide} accepts both ends`);
assert.strictEqual(TC.isValidCustomColors(slide, ['#000000']), false,
`${slide} does not accept one`);
}
assert.deepStrictEqual(TC.colorsInCategory('dark'), ['midnight', 'dark', 'moderndark', 'exodark', 'cleandark']);
assert.strictEqual(TC.colorsInCategory('flat').length, 9);
assert.deepStrictEqual(TC.colorsInCategory('special'),
['relax', 'corteza', 'appleglasspastel', 'modern', 'cleanlight']);
});
test('categoryOf maps each color, null for unknown', () => {
assert.strictEqual(TC.categoryOf('belize'), 'flat');
assert.strictEqual(TC.categoryOf('clearblue'), 'clear');
assert.strictEqual(TC.categoryOf('moderndark'), 'dark');
assert.strictEqual(TC.categoryOf('corteza'), 'special');
assert.strictEqual(TC.categoryOf('nope'), null); // negative
assert.strictEqual(TC.categoryOf(undefined), null); // negative
});
test('custom colors: flat=1, clear=2, dark/special=0', () => {
assert.strictEqual(TC.customColorCount('flat'), 1);
assert.strictEqual(TC.customColorCount('clear'), 2);
assert.strictEqual(TC.customColorCount('dark'), 0); // negative
assert.strictEqual(TC.customColorCount('special'), 0); // negative
assert.strictEqual(TC.allowsCustomColor('flat'), true);
assert.strictEqual(TC.allowsCustomColor('clear'), true);
assert.strictEqual(TC.allowsCustomColor('dark'), false); // negative
assert.strictEqual(TC.allowsCustomColor('special'), false); // negative
});
test('isValidCustomColors enforces category + count + hex', () => {
// flat: exactly one hex
assert.strictEqual(TC.isValidCustomColors('belize', ['#0a1b2c']), true);
assert.strictEqual(TC.isValidCustomColors('belize', ['#0a1b2c', '#ffffff']), false); // too many
assert.strictEqual(TC.isValidCustomColors('belize', []), false); // too few
assert.strictEqual(TC.isValidCustomColors('belize', ['red']), false); // not hex
assert.strictEqual(TC.isValidCustomColors('belize', ['#fff']), false); // short hex
// clear: exactly two hex (color slide)
assert.strictEqual(TC.isValidCustomColors('clearblue', ['#000000', '#ffffff']), true);
assert.strictEqual(TC.isValidCustomColors('clearblue', ['#000000']), false); // too few
// dark/special: never allowed
assert.strictEqual(TC.isValidCustomColors('dark', ['#000000']), false);
assert.strictEqual(TC.isValidCustomColors('corteza', ['#000000']), false);
assert.strictEqual(TC.isValidCustomColors('unknown', ['#000000']), false);
});
// --- source guard: the partition covers ALLOWED_BOARD_COLORS exactly ---
test('partition equals config/const.js ALLOWED_BOARD_COLORS (no gaps/extras)', () => {
const repoRoot = path.resolve(__dirname, '..');
const src = fs.readFileSync(path.join(repoRoot, 'config/const.js'), 'utf8');
const block = src.slice(src.indexOf('ALLOWED_BOARD_COLORS = ['));
const arr = block.slice(0, block.indexOf(']'));
const allowed = (arr.match(/'([a-z]+)'/g) || []).map(s => s.replace(/'/g, ''));
const union = TC.THEME_CATEGORY_ORDER.flatMap(c => TC.colorsInCategory(c));
assert.deepStrictEqual([...union].sort(), [...allowed].sort(),
'every board color is categorized exactly once and no extras exist');
});
console.log(`\nAll ${passed} theme-category tests passed`);