Files
wekan/tests/openCardPresence.test.cjs
T
Lauri Ojansivu 036ac4f56b #6808 follow-up: a card deleted elsewhere also leaves the card's address.
Found by the #6808 browser test: when an opened card really is deleted,
its window is destroyed with its data - usually before the server has
answered whether the card is gone - and the confirmation was dropped
for a destroyed window, so the window closed but the address stayed
the card's. The question is asked outside the window now
(confirmGoneCard, waiting for a settled connection and login), and the
window's end asks it too when the card is missing; the close
(closeGoneCard) clears the window, the popup and the address. A card
that only left for a reconnect still answers available and stays.

Thanks to brlin-tw and xet7 !
2026-10-27 16:32:52 +02:00

50 lines
1.8 KiB
JavaScript

'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { openCardIsUnavailable } = require('../models/lib/openCardPresence');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
test('an existing card on its original board remains open', () => {
assert.strictEqual(openCardIsUnavailable({ _id: 'c1', boardId: 'b1' }, 'b1'), false);
});
test('#3114: a remotely removed card closes', () => {
assert.strictEqual(openCardIsUnavailable(null, 'b1'), true);
assert.strictEqual(openCardIsUnavailable(undefined, 'b1'), true);
});
test('#3114: a card remotely moved to another board closes', () => {
assert.strictEqual(openCardIsUnavailable({ _id: 'c1', boardId: 'b2' }, 'b1'), true);
});
test('missing opening context closes defensively', () => {
assert.strictEqual(openCardIsUnavailable({ _id: 'c1', boardId: 'b1' }, null), true);
});
test('card details clears desktop, mobile route and popup state', () => {
const source = fs.readFileSync(
path.join(__dirname, '../client/components/cards/cardDetails.js'),
'utf8',
);
assert.ok(source.includes("ReactiveCache.getCard(openedCardId)"));
assert.ok(source.includes("Session.get('openCards')"));
assert.ok(source.includes("Session.set('currentCard', null)"));
// #6745: cleared to null like every route does, not deleted - a delete then a
// set(null) is a change that re-ran every minicard's currentBoard helpers.
assert.ok(source.includes("Session.set('popupCardId', null)"));
assert.ok(!source.includes("Session.delete('popupCardId')"));
// #6808: the close is closeGoneCard(cardId, boardId), outside the window
// so it also runs after the window went with its data.
assert.ok(source.includes('Utils.goBoardId(boardId)'));
});
console.log(`\nopenCardPresence: ${passed} tests passed`);