Files
wekan/tests/listSwimlaneColorSubpath.test.cjs
T
Lauri Ojansivu 998a9cc336 Let a list colour the cards that have no colour of their own.
The reporter coloured lists by stage and wanted cards to follow: "by merely
dragging cards around the colors would change". The only way was a script
that rewrote every card's colour through the API, again after every move.
A list's colour popup now has "Cards without a colour of their own use this
colour". Such cards are shown in the list's colour, and nothing is written
to them: a card dragged to another list takes that list's colour, and a
card's own colour always wins. models/lib/cardDisplayColor.js decides; the
card colour helpers use it from the list the card is shown in.

tests/cardDisplayColor.test.cjs covers the rule; the guards that pinned the
old colour code now pin it through the new helper. New text is in English,
pending Transifex.

Thanks to C0rn3j and xet7 !

Fixes #4756.
2026-10-08 12:15:49 +03:00

84 lines
2.9 KiB
JavaScript

'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const read = (relative) =>
fs.readFileSync(path.join(__dirname, '..', relative), 'utf8');
const lists = read('client/components/lists/listHeader.js');
const swimlanes = read('client/components/swimlanes/swimlaneHeader.js');
const listMarkup = read('client/components/lists/listHeader.jade');
const swimlaneMarkup = read('client/components/swimlanes/swimlaneHeader.jade');
const browser = read('tests/playwright/specs/36-subpath-colors.e2e.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
function popupEvents(source, templateName) {
const start = source.indexOf(`Template.${templateName}.events({`);
assert.ok(start >= 0, `${templateName} events exist`);
return source.slice(start, source.indexOf('\n});', start) + 4);
}
test('#4652 list color submit and click paths both prevent navigation', () => {
const events = popupEvents(lists, 'setListColorPopup');
assert.match(
events,
/'submit form'\(event, tpl\) \{\s*event\.preventDefault\(\)/,
);
assert.match(
events,
/'click \.js-submit'\(event, tpl\) \{\s*event\.preventDefault\(\)/,
);
// #4756: both paths save the colour (and whether cards follow it) through
// saveListColor, which still calls the list's setColor.
assert.match(
events,
/await saveListColor\(tpl, tpl\.currentColor\.get\(\)\)/,
);
assert.match(lists, /async function saveListColor\(tpl, color\) \{\s*await tpl\.currentList\.setColor\(color\);/);
assert.match(listMarkup, /button\.primary\.confirm\.js-submit/);
});
test('#4652 swimlane color submit and click paths both prevent navigation', () => {
const events = popupEvents(swimlanes, 'setSwimlaneColorPopup');
assert.match(
events,
/'submit form'\(event, tpl\) \{\s*event\.preventDefault\(\)/,
);
assert.match(
events,
/'click \.js-submit'\(event, tpl\) \{\s*event\.preventDefault\(\)/,
);
assert.match(
events,
/await tpl\.currentSwimlane\.setColor\(tpl\.currentColor\.get\(\)\)/,
);
assert.match(swimlaneMarkup, /button\.primary\.confirm\.js-submit/);
});
test('negative: card-independent fixes do not use absolute or root URLs', () => {
for (const events of [
popupEvents(lists, 'setListColorPopup'),
popupEvents(swimlanes, 'setSwimlaneColorPopup'),
]) {
assert.doesNotMatch(events, /ROOT_URL|rootUrl|location\.|window\.|href/);
}
});
test('Firefox browser regression covers both mutations and retains the prefix', () => {
assert.match(browser, /PATH_PREFIX/);
assert.match(browser, /js-set-color-list/);
assert.match(browser, /js-set-swimlane-color/);
assert.match(browser, /findOne\('lists'/);
assert.match(browser, /findOne\('swimlanes'/);
assert.match(browser, /toHaveURL/);
});
console.log(`\nlistSwimlaneColorSubpath: all ${passed} tests passed`);