mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Bind card and board identifiers explicitly on links rendered under lexical each loops. Open the subscribed card popup from the link rather than the unrelated outer Blaze data context, while preserving modified-click navigation. Regression tests cover outer-context mismatch, nested click targets, missing identifiers, modified clicks, and sequential card popup selection on both pages. The fresh bundle passes both page regressions in Chromium, Firefox and WebKit using polling reactivity. Thanks to Mathia2 and xet7 ! Fixes #6702,
48 lines
2.4 KiB
JavaScript
48 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
const { test } = require('node:test');
|
|
|
|
for (const [name, selector] of [
|
|
['myCards', 'js-minicard'], ['myAttachments', 'js-my-attachment-card'],
|
|
]) {
|
|
const source = fs.readFileSync(`client/components/main/${name}.js`, 'utf8');
|
|
const body = source.match(new RegExp(`'click \\.${selector}'\\(evt\\)\\s*\\{([\\s\\S]*?)\\n \\},`))[1];
|
|
function run(dataset, overrides = {}) {
|
|
const calls = [];
|
|
let ready;
|
|
const handler = vm.runInNewContext(`(function(evt) {${body}\n})`, {
|
|
// each card in ... does not change the outer data context (#6702).
|
|
Blaze: { getData: () => ({ _id: 'wrong-outer-context' }) },
|
|
Meteor: { subscribe: (name, id, callbacks) => { calls.push([name, id]); ready = callbacks.onReady; } },
|
|
Session: { set: (...args) => calls.push(args) },
|
|
Popup: { isOpen: () => false, open: name => () => calls.push(['open', name]) },
|
|
});
|
|
handler({ button: 0, currentTarget: { dataset }, target: { dataset: {} },
|
|
preventDefault: () => calls.push(['prevent']), ...overrides });
|
|
return { calls, ready: () => ready?.() };
|
|
}
|
|
test(`${name}: opens the clicked card after subscription, ignoring the outer context`, () => {
|
|
const result = run({ cardId: 'chosen-card', boardId: 'chosen-board' });
|
|
assert.deepEqual(result.calls, [['prevent'], ['popupCardData', 'chosen-card']]);
|
|
result.ready();
|
|
assert.deepEqual(result.calls.slice(2), [
|
|
['popupCardId', 'chosen-card'], ['popupCardBoardId', 'chosen-board'], ['open', 'cardDetails'],
|
|
]);
|
|
});
|
|
test(`${name}: missing identifiers and modified clicks keep native link behavior`, () => {
|
|
for (const data of [{}, { cardId: 'card' }, { boardId: 'board' }]) {
|
|
assert.deepEqual(run(data).calls, []);
|
|
}
|
|
for (const modifiers of [{ ctrlKey: true }, { metaKey: true }, { shiftKey: true }, { altKey: true }, { button: 1 }]) {
|
|
assert.deepEqual(run({ cardId: 'card', boardId: 'board' }, modifiers).calls, []);
|
|
}
|
|
});
|
|
test(`${name}: the link supplies both identifiers from the lexical card`, () => {
|
|
const jade = fs.readFileSync(`client/components/main/${name}.jade`, 'utf8');
|
|
assert.match(jade, new RegExp(`a[^\\n]*\\.${selector}\\([^\\n]*href=card\\.originRelativeUrl[^\\n]*data-card-id=card\\._id[^\\n]*data-board-id=card\\.boardId`));
|
|
});
|
|
}
|