Files
wekan/tests/wipLimitPopup.test.cjs
T
Lauri Ojansivu c5d13889b6 Fix #6465: the three UI bugs reported today - checkboxes, WIP limit, sidebar rows.
WIP-LIMIT POPUP: "the checkbox can not be unchecked and the counter always falls
back to 1". One cause for both. models/lists.js getWipLimit() read the list back
through `ReactiveCache.getList(this._id)`, and on the SERVER that getter is
ASYNC - it returns a promise, and a promise has no `wipLimit` - so the helper
answered 0 for every option, every time. `enableWipLimit` therefore saw value 0
and reset the limit to 1 on every click, and toggled `!enabled` where `enabled`
was always 0, so every click turned the limit ON. The document is `this`, so the
server needs no lookup at all - and a toggle wants the state as it was when the
click happened, not after its own write. The client keeps the lookup: it is what
makes the popup's tick and number follow the change. Apply now also refuses a
limit that is not a usable number instead of sending NaN, which passes
`check(limit, Number)` and dies in the schema with nothing to show the user.

ADMIN PANEL / ATTACHMENTS CHECKBOXES: every checkbox on those panes - Backup's
three, each storage's Enabled and Read, the S3 path-style flag, the avatar-upload
block - drew as a grey rotated RECTANGLE instead of a green tick. They were
native `<input type="checkbox">` styled into WeKan's material checkbox, which
needs the browser to drop its own rendering for `appearance: none`; where it does
not, the geometry applies and the colours do not, which is exactly that
rectangle. They are `.materialCheckBox` divs now, the same markup as the rest of
WeKan, with no native rendering to lose. Two of them could not be unchecked for a
second reason: their state was written as `checked="{{filesystemRead}}"`, a
quoted STRING - and `checked="false"` is checked in HTML.

SIDEBAR CHECKBOX ROWS: "checkboxes and text don't fit well". A row is
`a.flex > i.fa + span`, and `.flex` is only `display: flex` - no alignment, no
gap - so the box glyph touched the first letter of its label and sat on a
different line from it. `align-items: center` and a 6px gap, with a fixed glyph
width so every row's label starts at the same x whether its box is a square or a
tick.

tests/wipLimitPopup.test.cjs and tests/adminAttachmentCheckboxes.test.cjs pin
all of it.

Thanks to Alishara and xet7 !

Fixes #6465,
2026-07-28 12:13:21 +03:00

90 lines
3.8 KiB
JavaScript

'use strict';
// Plain-Node guard for the WIP-limit popup (#6465, and issue 6533's neighbour in
// the same report). Run: node tests/wipLimitPopup.test.cjs
//
// Two symptoms, one cause: "the checkbox can not be unchecked" and "the counter
// always falls back to 1".
//
// models/lists.js getWipLimit() read the list back through
// `ReactiveCache.getList(this._id)`. On the SERVER that getter is async - it
// returns a PROMISE, and a promise has no `wipLimit` - so the helper answered 0
// for every option, on every call. The `enableWipLimit` method then:
//
// * saw value 0 and reset the limit to 1 on every click;
// * saw enabled 0 and called toggleWipLimit(!0) = toggleWipLimit(true), so
// every click turned the limit ON and none could turn it off.
//
// The document is `this`, so the server needs no lookup. The client keeps the
// lookup, because it is what makes the popup's helpers reactive.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
const model = read('models/lists.js');
const serverModel = read('server/models/lists.js');
const client = read('client/components/lists/listHeader.js');
let passed = 0;
function test(name, fn) {
try {
fn();
passed++;
console.log(' ok -', name);
} catch (err) {
console.error(` FAIL - ${name}\n ${err.message}`);
process.exitCode = 1;
}
}
console.log('wipLimitPopup:');
// The helper's body, so the assertions are about IT and not about the file.
function helper() {
const at = model.indexOf('getWipLimit(option) {');
assert.notStrictEqual(at, -1, 'getWipLimit must exist');
return model.slice(at, model.indexOf('\n },', at));
}
test('the server reads the document it was given, not a promise', () => {
const body = helper();
assert.ok(/Meteor\.isServer \? this :/.test(body),
'on the server the document is `this` - ReactiveCache.getList() is async there');
assert.ok(/ReactiveCache\.getList\(this\._id\) \|\| this/.test(body),
'and on the client the reactive lookup stays, so the popup follows the change');
assert.ok(!/^\s*const list = ReactiveCache\.getList\(this\._id\);\s*$/m.test(body),
'the unconditional lookup is what returned a promise on the server');
});
test('a toggle is still a toggle, and 0 still becomes 1', () => {
const at = serverModel.indexOf('async enableWipLimit(listId)');
assert.notStrictEqual(at, -1, 'the method must exist');
const method = serverModel.slice(at, serverModel.indexOf('\n },', at));
assert.ok(/toggleWipLimit\(!\(await list\.getWipLimit\('enabled'\)\)\)/.test(method),
'it toggles the stored state - which now IS the stored state');
assert.ok(/getWipLimit\('value'\)\) === 0/.test(method) && /setWipLimit\(1\)/.test(method),
'a list with no limit yet starts at 1');
assert.ok(/hasAdmin\(this\.userId\)/.test(method), 'and only a board admin may do it');
});
test('a limit that is not a usable number never reaches the document', () => {
// NaN passes `check(limit, Number)` - it IS a number - and the schema then
// refuses the write with nothing to show the user.
const at = serverModel.indexOf('async applyWipLimit(listId, limit)');
const method = serverModel.slice(at, serverModel.indexOf('\n },', at));
assert.ok(/!Number\.isFinite\(limit\) \|\| limit < 1/.test(method),
'the server clamps a non-number / below-one limit to 1');
const at2 = client.indexOf("'click .wip-limit-apply'");
const handler = client.slice(at2, client.indexOf('\n },', at2));
assert.ok(/!Number\.isFinite\(limit\) \|\| limit < 1 \|\| limit > 99/.test(handler),
'and the popup says so instead of sending it: the field is min=1 max=99');
assert.ok(/wip-limit-error/.test(handler), 'by opening the error popup it already has');
});
console.log(`\n${passed} tests passed`);