Files
wekan/tests/globalThemeColor.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

119 lines
6.0 KiB
JavaScript

'use strict';
// #5778: global per-user theme color override (Member Menu / Change Color).
// The feature is Blaze/CSS/Meteor-coupled, so this is a source guard that the pieces
// are wired end-to-end, plus a behavioural check of the two pure decisions:
// - globalThemeColorClass(): color -> `board-color-<color>` (or '' when unset)
// - the <body> autorun's rule: apply only when NOT on a board and a color is set.
//
// Run: node tests/globalThemeColor.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
// --- behavioural: the class mapping (mirror of Users.globalThemeColorClass) ---
function globalThemeColorClass(color) {
return color ? `board-color-${color}` : '';
}
test('globalThemeColorClass maps a color to its board-color class, else empty', () => {
assert.strictEqual(globalThemeColorClass('moderndark'), 'board-color-moderndark');
assert.strictEqual(globalThemeColorClass('dark'), 'board-color-dark');
assert.strictEqual(globalThemeColorClass(null), ''); // negative
assert.strictEqual(globalThemeColorClass(''), ''); // negative
assert.strictEqual(globalThemeColorClass(undefined), ''); // negative
});
// --- behavioural: the autorun decision (mirror of globalThemeColor.js) ---
function bodyClass(color, onBoard) {
return !onBoard && color ? `board-color-${color}` : null;
}
test('body gets the global class only OFF a board and only when a color is set', () => {
assert.strictEqual(bodyClass('dark', false), 'board-color-dark'); // All Boards etc.
assert.strictEqual(bodyClass('dark', true), null); // on a board: board color wins
assert.strictEqual(bodyClass(null, false), null); // no override set
assert.strictEqual(bodyClass('', false), null); // negative
});
// --- source guards: end-to-end wiring ---
test('user model: schema field + helpers + setter', () => {
const m = read('models/users.js');
assert.ok(/'profile\.globalThemeColor'/.test(m), 'schema field');
assert.ok(/getGlobalThemeColor\(\)/.test(m), 'getter');
assert.ok(/globalThemeColorClass\(\)/.test(m), 'class helper');
assert.ok(/setGlobalThemeColor\(color\)/.test(m), 'setter helper');
assert.ok(/\$unset:\s*{\s*'profile\.globalThemeColor'/.test(m), 'clears the override');
});
test('server method validates against BOARD_COLORS and is auth-guarded', () => {
const s = read('server/models/users.js');
const i = s.indexOf('setGlobalThemeColor(color');
assert.ok(i !== -1, 'server method');
const body = s.slice(i, i + 900);
assert.ok(/not-logged-in/.test(body), 'requires login');
// NEGATIVE guard: an unknown color must be rejected, not written as a CSS class.
assert.ok(/BOARD_COLORS\.includes\(color\)/.test(body), 'validates the color');
assert.ok(/invalid-color/.test(body), 'rejects unknown colors');
// custom colors are validated (flat/clear + hex) before storage.
assert.ok(/isValidCustomColors\(color, customColors\)/.test(body), 'validates custom colors');
});
test('member menu has Change Color, opening the shared theme picker (scope=global)', () => {
const jade = read('client/components/users/userHeader.jade');
assert.ok(/js-change-color/.test(jade), 'menu entry');
assert.ok(/template\(name="changeColorPopup"\)/.test(jade), 'popup template');
assert.ok(/\+themeColorPicker\(scope="global"\)/.test(jade), 'renders the shared picker');
const js = read('client/components/users/userHeader.js');
assert.ok(/Popup\.open\('changeColor'\)/.test(js), 'opens the popup');
});
test('body autorun applies the global override EVERYWHERE (wins over board color)', () => {
const j = read('client/components/main/globalThemeColor.js');
assert.ok(/board-color-\$\{globalColor\}/.test(j), 'builds the board-color class from the global override');
// A set global override returns early -> applied regardless of board context.
assert.ok(/if \(globalColor\)/.test(j), 'global override wins everywhere');
// Falls back to the current board custom colors only when there is NO global.
assert.ok(/Session\.get\('currentBoard'\)/.test(j) && /customThemeColors/.test(j), 'board fallback when unset');
assert.ok(/--theme-accent/.test(j), 'sets the custom-color CSS variable');
});
test('header + board-wrapper take the theme class from ONE helper', () => {
// They used to spell the order out in the template - global override, else board
// colour - which is why the SITE theme (docs/Features/Theme/Change-Color.md, layer 2)
// coloured the buttons but left both top bars on the default: nothing there read
// it. One helper now answers for all of them, so the order cannot drift apart.
const h = read('client/components/main/header.jade');
const headerMatches = h.match(/class="\{\{themeColorClass\}\}"/g) || [];
assert.ok(headerMatches.length >= 2, 'both #header and #header-quick-access use the helper');
const bb = read('client/components/boards/boardBody.jade');
assert.ok(/class="\{\{themeColorClass\}\}"/.test(bb),
'.board-wrapper uses it too (so board content is themed)');
// …and the helper keeps the order: user override, then the board, then the site.
const j = read('client/components/main/globalThemeColor.js');
const helper = j.slice(j.indexOf("Template.registerHelper('themeColorClass'"),
j.indexOf('Meteor.startup('));
const iOwn = helper.indexOf('globalThemeColor');
const iBoard = helper.indexOf('boardClass');
const iSite = helper.indexOf('setting.themeColor');
assert.ok(iOwn > 0 && iBoard > iOwn && iSite > iBoard,
'the user override wins, then the board colour, then the site theme');
});
test('i18n has the new strings', () => {
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
assert.strictEqual(en['change-color'], 'Change Color');
assert.ok(typeof en['theme-default'] === 'string' && en['theme-default'].length > 0);
});
console.log(`\nAll ${passed} global-theme-color (#5778) tests passed`);