Files
wekan/tests/requestedAssignedByVisible.test.cjs
T
Lauri Ojansivu 5dd0b11f7c Keep translation repairs and card visibility guards aligned with reviewed changes
Preserve the newer Traditional Chinese wording in historical repair records. Locate the card read-only branch by its matching conditional rather than fixed indentation after optional field grouping.

Verified all 1169 Node suites pass, translation pull/fill protection passes, and missing requester or assigner avatars still fail the repaired guard.

Thanks to xet7 !
2026-09-17 14:20:35 +03:00

54 lines
2.3 KiB
JavaScript

'use strict';
// Assigned By shows when there IS an assigner.
// Run: node tests/requestedAssignedByVisible.test.cjs
//
// The read-only branch of Assigned By - what a reader who may not edit the card
// sees - was written `else if getRequestedBy` above `= getAssignedBy`. So a card
// with an assigner and no requester showed neither, and the section drew its
// heading with nothing under it.
//
// The two fields also carry selected board members, so read-only cards show
// their avatars whether or not the optional free-text value is present.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const jade = fs.readFileSync(
path.join(__dirname, '..', 'client/components/cards/cardDetails.jade'), 'utf8');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('requestedAssignedByVisible:');
test('each read-only branch shows its own selected people and optional text', () => {
for (const [label, people, text] of [
['requested-by', 'getRequesters', 'getRequestedBy'],
['assigned-by', 'getAssigners', 'getAssignedBy'],
]) {
const block = jade.slice(jade.indexOf(`| {{_ '${label}'}}`));
// Grouping optional fields under Members (#6696) changed indentation.
// Match the else belonging to canModifyCard, not the nested editor's else
// or a fixed column/character count that changes with the surrounding UI.
const branch = block.match(/\n( +)if canModifyCard\n[\s\S]*?\n\1else\n((?:(?:\1 +[^\n]*|)\n)+)/);
assert.ok(branch, `${label} read-only branch`);
const readOnly = branch[2];
assert.ok(new RegExp(`each userId in ${people}`).test(readOnly), `${label} avatars`);
assert.ok(new RegExp(`if ${text}[\\s\\S]*= ${text}`).test(readOnly), `${label} text`);
}
});
test('and both are added the way a person is added', () => {
// The same round + Members and Assignee use. This is what makes combining the
// four into one template the obvious next step rather than a rewrite.
for (const label of ['requested-by', 'assigned-by']) {
const block = jade.slice(jade.indexOf(`| {{_ '${label}'}}`), jade.indexOf(`| {{_ '${label}'}}`) + 1200);
assert.ok(/a\.member\.add-member\.card-details-item-add-button/.test(block),
`${label} keeps the + button`);
}
});
console.log(`\nrequestedAssignedByVisible: ${passed} tests passed`);