Files
wekan/tests/buttonThemeColors.test.cjs
T
Lauri Ojansivu 15157cde09 Member Settings / Change Settings: the button is Save, and it has a theme.
It said "Apply" while every other settings form in WeKan says Save, and it was
pure black. Both came from one line: the submit carried no `.primary` class, so
it fell to the BASE button rule in forms.css - whose fallback is `#000` - instead
of the primary rule beside it, which is the themed one
(`var(--theme-accent, #005377)`). The Change Language form directly above it in
the same popup uses `input.primary.wide`, which is the shape this now matches.

The test guards both halves on that one line, so a Save that loses its theme, or a
form that goes back to "Apply", fails.
2026-07-31 04:09:41 +03:00

70 lines
3.7 KiB
JavaScript

'use strict';
// Buttons must follow the user's theme (Member Settings → Change color sets
// --theme-accent on :root). The global button base and primary buttons hardcoded
// black/blue and ignored the theme; they now use var(--theme-accent, <fallback>)
// so the default look is unchanged but a theme override recolors them app-wide.
//
// Run: node tests/buttonThemeColors.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
let passed = 0;
function check(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
console.log('buttonThemeColors:');
check('forms.css: base button + primary buttons use var(--theme-accent)', () => {
const css = read('client/components/forms/forms.css');
// base button background themed (default black preserved as fallback)
assert.ok(/background:\s*var\(--theme-accent, #000\)/.test(css), 'base button background must be themed');
// primary button themed
assert.ok(/background:\s*var\(--theme-accent, #005377\)/.test(css), 'button.primary must be themed');
assert.ok(/background:\s*var\(--theme-accent, #004766\)/.test(css), 'button.primary:hover must be themed');
assert.ok(/background:\s*var\(--theme-accent, #01628c\)/.test(css), 'button.primary:active must be themed');
});
check('every settings form ends in a themed Save, not a black Apply', () => {
// Member Settings → Change Settings had a submit that carried NO `.primary`, so
// it fell to the base rule above - whose fallback is `#000`, a pure black button
// with no theme in it - and it was the one settings form in WeKan labelled
// "Apply" while the rest say Save. Both came from the same line.
const jade = read('client/components/users/userHeader.jade');
const at = jade.indexOf('js-apply-user-settings');
assert.ok(at > -1, 'the Change Settings submit must exist');
const button = jade.slice(jade.lastIndexOf('\n', at), jade.indexOf('\n', at));
assert.ok(/\.primary/.test(button),
'it must be .primary, or it renders with the base rule\'s black fallback');
assert.ok(/value="\{\{_ 'save'\}\}"/.test(button), 'and say Save');
assert.ok(!/'apply'/.test(button), 'not Apply');
// The Change Language form directly above it is the shape to match.
assert.ok(/input\.primary\.wide\(type="submit" value="\{\{_ 'save'\}\}"\)/.test(jade),
'the Change Language Save is the sibling this matches');
});
check('admin (settingBody) + People (peopleBody) buttons follow the theme accent', () => {
const sb = read('client/components/settings/settingBody.css');
assert.ok(/var\(--theme-accent, #005377\)/.test(sb), 'admin action button must be themed');
// People's own search button lived in the page-title bar (`.ext-box`), which is
// gone - an Admin Panel page is the left menu and the pane, nothing above them. Its
// search moved into the shared table page's controls row, so the buttons a People
// pane shows are that row's, themed in paginationControls.css.
const pb = read('client/components/settings/peopleBody.css');
assert.ok(!/\.ext-box/.test(pb), 'the title-bar rules must be gone, not left rotting');
const pager = read('client/components/main/paginationControls.css');
assert.ok(/background:\s*var\(--theme-accent/.test(pager),
'the shared controls buttons must be themed');
// no bare hardcoded WeKan-accent hexes remain in these two files
for (const [f, css] of [['settingBody.css', sb], ['peopleBody.css', pb]]) {
const bare = css.match(/(?<!, )(?<!\()#(?:01628c|005377|004766)(?!\))/g) || [];
assert.strictEqual(bare.length, 0, `${f} must have no un-themed accent hexes`);
}
});
console.log(`\n${passed} passed`);