Files
wekan/tests/themeCategories.test.cjs
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02: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/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`);