mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
The first attempt drew the checkmark with a pseudo-element over the box. That got the checked state right and lost the other two thirds of the checkbox: the plain grey square when unchecked, and the 0.2s morph between them that Announcement's "Active System-Wide Announcement" checkbox has. The rules are now `.materialCheckBox` and `.materialCheckBox.is-checked` applied to the input itself - the same square, the same morph into the same green tick, the same transition - with `appearance: none` as the only addition, to take the browser's own rendering out of it. A native Admin Panel checkbox and a WeKan one are now the same checkbox in every state. The test compares them declaration by declaration against forms.css, so a change to the material checkbox that is not carried over here fails rather than quietly leaving the two different again. Thanks to xet7 !
143 lines
7.5 KiB
JavaScript
143 lines
7.5 KiB
JavaScript
'use strict';
|
|
|
|
// ONE checkbox look for the whole Admin Panel.
|
|
//
|
|
// WeKan hides the native checkbox app-wide (forms.css) and draws its own square
|
|
// with a green tick — `.materialCheckBox`, which is what Admin Panel / Settings /
|
|
// Announcement shows. But several panes use a real <input type="checkbox">: the
|
|
// storage Read toggles, the Organizations and Teams feature columns, the Backup
|
|
// checkboxes, the Problems summary. Those were either invisible (nothing re-enabled
|
|
// them) or re-enabled pane by pane and then drawn by the BROWSER — on Ubuntu a big
|
|
// orange box that ignored the chosen theme entirely and matched nothing else on the
|
|
// page, at a different size in each pane.
|
|
//
|
|
// These are CSS source guards; there is no browser here to render anything.
|
|
//
|
|
// Run: node tests/adminCheckboxStyle.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
const rule = (css, selector) => {
|
|
const at = css.indexOf(selector);
|
|
assert.ok(at !== -1, `${selector} must exist`);
|
|
return css.slice(at, css.indexOf('}', at));
|
|
};
|
|
|
|
const admin = read('client/components/settings/settingBody.css');
|
|
const forms = read('client/components/forms/forms.css');
|
|
|
|
console.log('adminCheckboxStyle:');
|
|
|
|
test('the Admin Panel styles its native checkboxes itself', () => {
|
|
const box = rule(admin, '.setting-content input[type="checkbox"] {');
|
|
assert.ok(/appearance: none;/.test(box) && /-webkit-appearance: none;/.test(box),
|
|
'the browser\'s own rendering is taken out of it - that was the orange box');
|
|
// …and they are visible at all, which the app-wide rule otherwise prevents.
|
|
assert.ok(/visibility: visible;/.test(box) && /display: inline-block;/.test(box),
|
|
'and they are shown, which forms.css hides app-wide');
|
|
assert.ok(/\[type="checkbox"\]:not\(:checked\),\n\[type="checkbox"\]:checked \{[\s\S]*?display: none;/.test(forms),
|
|
'the app-wide hiding rule is still there for everything outside the Admin Panel');
|
|
});
|
|
|
|
test('an Admin Panel checkbox IS the material checkbox, declaration for declaration', () => {
|
|
// Not "looks a bit like it": every declaration of .materialCheckBox and of
|
|
// .materialCheckBox.is-checked must be here, so the unchecked square, the checked
|
|
// tick AND the `transition: 0.2s` that animates between them are the same. Drawing
|
|
// only a tick with a pseudo-element gets the checked state right and loses the
|
|
// other two - which is exactly what was wrong before.
|
|
const decls = block => new Set(block.split('\n')
|
|
.map(line => line.trim().replace(/;$/, ''))
|
|
.filter(line => line.includes(':') && !line.startsWith('/*') && !line.startsWith('*')));
|
|
const missing = (from, to) => [...decls(from)].filter(d => !decls(to).has(d));
|
|
|
|
const unchecked = rule(admin, '.setting-content input[type="checkbox"] {');
|
|
assert.deepStrictEqual(missing(rule(forms, '.materialCheckBox {'), unchecked), [],
|
|
'the unchecked box is the material one - the grey square, and the transition');
|
|
assert.ok(/transition: 0\.2s;/.test(unchecked), 'which is what animates the change');
|
|
|
|
const checked = rule(admin, '.setting-content input[type="checkbox"]:checked {');
|
|
assert.deepStrictEqual(missing(rule(forms, '.materialCheckBox.is-checked {'), checked), [],
|
|
'and the checked state is the material one: the square morphs into the tick');
|
|
|
|
// The tick is green, not the theme accent: WeKan's tick is green everywhere.
|
|
assert.ok(/border-bottom: 2px solid #3cb500;/.test(checked));
|
|
assert.ok(!/--theme-accent/.test(checked), 'the tick does not follow the theme');
|
|
});
|
|
|
|
test('grey icons and disabled states are handled', () => {
|
|
assert.ok(/body\.grey-icons-enabled \.setting-content input\[type="checkbox"\]:checked \{/.test(admin),
|
|
'grey icons grey the tick here too');
|
|
const disabled = rule(admin, '.setting-content input[type="checkbox"]:disabled {');
|
|
assert.ok(/opacity: 0\.6;/.test(disabled));
|
|
assert.ok(/:focus-visible/.test(admin), 'and a keyboard user can see the focus');
|
|
});
|
|
|
|
test('no pane re-enables or re-sizes checkboxes on its own any more', () => {
|
|
// Every pane that did picked its own size, which is why no two panes agreed.
|
|
for (const file of ['client/components/settings/attachments.css',
|
|
'client/components/settings/peopleBody.css',
|
|
'client/components/settings/tablePage.css',
|
|
'client/components/settings/adminReports.css']) {
|
|
const css = read(file);
|
|
for (const m of css.matchAll(/([^{}]*input\[type="checkbox"\][^{}]*)\{([^{}]*)\}/g)) {
|
|
const [, selector, body] = m;
|
|
// A pane may still say something about the LABEL beside a disabled box, and
|
|
// about spacing - but not about the checkbox's own size or visibility.
|
|
if (/\+ label/.test(selector)) continue;
|
|
assert.ok(!/width:|height:|visibility:|display: (inline-)?block/.test(body),
|
|
`${file}: ${selector.trim()} must leave the checkbox itself to the shared rule`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('the panes that use a native checkbox are the ones this is for', () => {
|
|
// If these ever move to the .materialCheckBox markup the rule can go; until then
|
|
// this is what it covers, and it names them so the reason is not lost.
|
|
const panes = {
|
|
'client/components/settings/attachments.jade': ['js-toggle-gridfs-read',
|
|
'js-toggle-filesystem-read', 'js-backup-attachments', 's3-read',
|
|
'js-avatars-upload-blocked'],
|
|
'client/components/settings/peopleBody.jade': ['js-toggle-org-feature',
|
|
'js-toggle-team-feature', 'selectUserChkBox'],
|
|
'client/components/settings/problemsSummary.jade': ['js-problem-check'],
|
|
};
|
|
for (const [file, classes] of Object.entries(panes)) {
|
|
const jade = read(file);
|
|
for (const cls of classes) {
|
|
assert.ok(jade.includes(cls), `${file}: ${cls} is one of the native checkboxes`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('a checkbox written as label > input gets its gap', () => {
|
|
// The `.materialCheckBox` markup is an anchor with a box and a span; a native one
|
|
// written as `label > input + text` has nothing between the box and the words.
|
|
const gap = rule(admin, '.setting-content label > input[type="checkbox"] {');
|
|
assert.ok(/margin-inline-end: 6px;/.test(gap), 'logical margin, so RTL is right too');
|
|
});
|
|
|
|
test('the Admin Panel Save buttons are one button, in the panes and in the popups', () => {
|
|
// The panes' Save is a button.primary; the popups' is an input[type=submit].primary
|
|
// in a flex row, and the `.wide` that was meant to size it never applied - the rule
|
|
// for it in forms.css is a DESCENDANT selector, which an input can never match.
|
|
const save = rule(admin, '.setting-content .content-body .main-body .setting-detail button.primary,');
|
|
for (const popup of ['editUserPopup', 'editOrgPopup', 'editTeamPopup']) {
|
|
assert.ok(save.includes(`.pop-over[data-popup='${popup}'] .buttonsContainer input[type="submit"].primary`),
|
|
`${popup}'s Save is styled with the panes' Save, not separately`);
|
|
}
|
|
assert.ok(/background: var\(--theme-accent, #005377\);/.test(save),
|
|
'the theme accent, like every other Admin Panel button');
|
|
assert.ok(/padding: 9px 35px;/.test(save) && /font-weight: 700;/.test(save),
|
|
'and the same size and weight');
|
|
// …with the hover/focus and active states listed for both as well.
|
|
assert.ok(/button\.primary:hover,[\s\S]*?input\[type="submit"\]\.primary:hover/.test(admin));
|
|
assert.ok(/button\.primary:active,[\s\S]*?input\[type="submit"\]\.primary:active/.test(admin));
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|