mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 20:45:07 -05:00
Reported directly: after adding a label to an opened card, clicking it in
the Labels popup no longer made it wider or applied it to the card. It
worked in the previous release.
The reorderable card detail sections (131514d61) are rendered by an `each`
over the board's stored section order. The plain `each
orderedCardFieldSections` form sets the data context of everything inside
it to the current item - the section NAME string ("labels", "dates", ...) -
so every section template, and every popup opened from one, received a
string where it expected the card. Popup.open uses the clicked element's
data context, so the Labels popup's `templateInstance.data` was "labels":
`card.toggleLabel` was undefined and the click handler returned silently,
`isLabelSelected ../_id` looked up `_id` on a string, and the section's own
`each labels` / `each stickers` / `each getLocations` rendered nothing. The
earlier fixes this session (global helpers, missing imports, the sortable
`stop` handler) each removed a real exception on this path but could not
restore the toggle, because the popup still had no card.
Switched the loop to `each section in orderedCardFieldSections`, the form
already used elsewhere in this file, which keeps `this` as the card and
exposes the item as `section`.
tests/cardFieldSectionsKeepCardContext.test.cjs pins the `in` form and that
every branch compares `section`; tests/cardFieldOrder.test.cjs updated to
the new loop text (its intent - the order-driven loop - is unchanged).
Thanks to xet7 !
58 lines
2.8 KiB
JavaScript
58 lines
2.8 KiB
JavaScript
'use strict';
|
|
|
|
// Regression guard: reported directly - after adding a label to an opened
|
|
// card, clicking it in the Labels popup no longer made it wider/applied it
|
|
// to the card. It had worked in the previous release.
|
|
//
|
|
// The card detail view's reorderable sections (Labels, Dates, Members,
|
|
// Custom Fields, Description) are rendered with an `each` over the board's
|
|
// stored section order. The plain `each orderedCardFieldSections` form sets
|
|
// the DATA CONTEXT of everything inside it to the current item - the section
|
|
// NAME string ("labels", "dates", ...) - so `+cardFieldSectionLabels` and the
|
|
// Labels popup opened from its `.js-add-labels` link (Popup.open uses the
|
|
// clicked element's data context) both received a string where they
|
|
// expected the card. `templateInstance.data.toggleLabel` was then undefined
|
|
// and the click handler returned silently; `isLabelSelected ../_id` looked
|
|
// up `_id` on a string; the section's own `each labels`/`each stickers`/
|
|
// `each getLocations` rendered nothing.
|
|
//
|
|
// The `each section in orderedCardFieldSections` form keeps `this` as the
|
|
// card and exposes the item as `section`. This pins that form.
|
|
//
|
|
// Run: node tests/cardFieldSectionsKeepCardContext.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const jade = fs.readFileSync(
|
|
path.join(ROOT, 'client', 'components', 'cards', 'cardDetails.jade'), 'utf8');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
console.log('cardFieldSectionsKeepCardContext:');
|
|
|
|
test('the section loop uses the context-preserving `each section in ...` form', () => {
|
|
assert.ok(/^\s*each section in orderedCardFieldSections\s*$/m.test(jade));
|
|
assert.ok(!/^\s*each orderedCardFieldSections\s*$/m.test(jade),
|
|
'the plain `each` form replaces the card data context with the section name (negative)');
|
|
});
|
|
|
|
test('every section branch compares the loop variable, not `this`', () => {
|
|
const start = jade.indexOf('each section in orderedCardFieldSections');
|
|
const block = jade.slice(start, jade.indexOf('.card-checklist-attachmentGalleries', start));
|
|
const branches = [...block.matchAll(/if \$eq (\S+) "/g)].map(m => m[1]);
|
|
assert.ok(branches.length >= 5, `expected the five section branches, found ${branches.length}`);
|
|
assert.deepStrictEqual([...new Set(branches)], ['section']);
|
|
});
|
|
|
|
test('the Labels popup click handler still relies on the popup data being the card', () => {
|
|
const labels = fs.readFileSync(
|
|
path.join(ROOT, 'client', 'components', 'cards', 'labels.js'), 'utf8');
|
|
assert.ok(/const card = templateInstance\.data;[\s\S]*?await card\.toggleLabel\(labelId\)/.test(labels));
|
|
});
|
|
|
|
console.log(`\ncardFieldSectionsKeepCardContext: ${passed} tests passed`);
|