Files
wekan/tests/cardFieldSectionHelperScope.test.cjs
T
Lauri Ojansivu 0c538bb924 Fix "No such function: isDateFormat" and 11 siblings breaking the card popup.
Reported directly: clicking a minicard did not open the card popup, with
the browser console showing "Error: No such function: isDateFormat" from
Template.cardFieldSectionDates. cardDetails.jade was split into several
per-section templates (cardFieldSectionLabels/Dates/Members/
DependenciesAndSort/CustomFields/VoteAndPoker), plus cardDetailsActionsPopup
and activities.jade are separate templates entirely - but twelve helpers
those templates actually call (isDateFormat, canShowCustomFieldsOnCard,
stickers, isWatching, dueDateChangeCount, getLocations, getDependencyCards,
customFieldsGrid, showActivities, showVotingButtons,
showPlanningPokerButtons, currentSwimlaneListsSorted, isCurrentListId) were
only ever registered on Template.cardDetails.helpers - template-local, so
invisible to every template that isn't cardDetails itself. Blaze only
surfaces this the moment that piece of UI actually renders (an
autorun/Tracker throw, not a build error), which is why it passed the
Node test suite and even a `meteor build` cleanly and only broke live.

Moved all twelve to Template.registerHelper (global), matching the
pattern the file already uses for isSectionOpen (this file) and
canModifyCard (client/config/blazeHelpers.js) - both deliberately global
for the same reason. The remaining Template.cardDetails.helpers entries
(orderedCardFieldSections, cardMaximized, cardCollapsed, presentParentTask,
linkForCard, isVerticalScrollbars, isLoaded) are confirmed used only from
cardDetails.jade itself, so they stay template-local.

tests/cardFieldSectionHelperScope.test.cjs pins all twelve as globally
registered and confirms none are shadowed by a stale local copy.
tests/recentIssueRegressions.test.cjs's currentSwimlaneListsSorted
extraction updated for the new registerHelper shape (behavior unchanged).

Verified against a real Meteor boot (`meteor run`) in-sandbox.

Thanks to xet7 !
2026-09-11 00:00:02 +03:00

86 lines
4.1 KiB
JavaScript

'use strict';
// Regression guard: clicking a minicard could throw "No such function:
// isDateFormat" (or any of the eleven other helpers fixed alongside it) and
// leave the card popup half-rendered - or not open at all - because a
// TEMPLATE-LOCAL Blaze helper (Template.cardDetails.helpers) was used from a
// DIFFERENT template. cardDetails.jade was split into cardFieldSectionLabels/
// Dates/Members/DependenciesAndSort/CustomFields/VoteAndPoker - each its own
// `template(name=...)` block - and cardDetailsActionsPopup and
// activities.jade are separate templates entirely; a helper only registered
// on Template.cardDetails is invisible there. Blaze only surfaces this at
// the moment that piece of UI actually renders, so it compiled fine, passed
// every existing test, and only broke in the browser.
//
// This is a source-read test (no Meteor/Blaze runtime available under plain
// Node): it checks the SHAPE directly - each of these names must be
// registered with Template.registerHelper (global, visible everywhere), not
// buried inside a single template's own .helpers({...}) call.
//
// Run: node tests/cardFieldSectionHelperScope.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('cardFieldSectionHelperScope:');
test('every helper used by a cardFieldSection*/cardDetailsActionsPopup template is registered globally', () => {
const src = fs.readFileSync(
path.join(ROOT, 'client', 'components', 'cards', 'cardDetails.js'), 'utf8');
const names = [
'isDateFormat', 'canShowCustomFieldsOnCard', 'stickers', 'isWatching',
'dueDateChangeCount', 'getLocations', 'getDependencyCards',
'customFieldsGrid', 'showActivities', 'showVotingButtons',
'showPlanningPokerButtons', 'currentSwimlaneListsSorted', 'isCurrentListId',
];
const missing = names.filter(name =>
!new RegExp(`Template\\.registerHelper\\(['"]${name}['"]`).test(src));
assert.deepStrictEqual(missing, [],
`these helpers are used outside Template.cardDetails but are not registered globally: ${missing.join(', ')}`);
});
test('none of those globally-registered names are ALSO duplicated inside Template.cardDetails.helpers '
+ '(negative - a stale local copy would shadow the global one with different behavior)', () => {
const src = fs.readFileSync(
path.join(ROOT, 'client', 'components', 'cards', 'cardDetails.js'), 'utf8');
const localBlockStart = src.indexOf('Template.cardDetails.helpers({');
assert.ok(localBlockStart !== -1, 'Template.cardDetails.helpers({...}) must still exist');
// The local block is the LAST top-level construct of its kind in this
// file; slice to the matching close by counting braces from its opening.
let depth = 0;
let end = localBlockStart;
for (let i = src.indexOf('{', localBlockStart); i < src.length; i += 1) {
if (src[i] === '{') depth += 1;
else if (src[i] === '}') {
depth -= 1;
if (depth === 0) { end = i; break; }
}
}
const localBlock = src.slice(localBlockStart, end);
const globalNames = [
'isDateFormat', 'canShowCustomFieldsOnCard', 'stickers', 'isWatching',
'dueDateChangeCount', 'getLocations', 'getDependencyCards',
'customFieldsGrid', 'showActivities', 'showVotingButtons',
'showPlanningPokerButtons', 'currentSwimlaneListsSorted', 'isCurrentListId',
];
const shadowed = globalNames.filter(name =>
new RegExp(`^\\s*${name}\\s*\\(`, 'm').test(localBlock));
assert.deepStrictEqual(shadowed, [],
`these globally-registered helpers are ALSO defined inside Template.cardDetails.helpers, `
+ `shadowing the global one for cardDetails itself: ${shadowed.join(', ')}`);
});
test('cardFieldSectionDates.jade\'s date-format selector still calls isDateFormat', () => {
const jade = fs.readFileSync(
path.join(ROOT, 'client', 'components', 'cards', 'cardDetails.jade'), 'utf8');
assert.ok(/isDateFormat 'YYYY-MM-DD'/.test(jade));
});
console.log(`\ncardFieldSectionHelperScope: ${passed} tests passed`);