Files
wekan/tests/cardWindowDiff.test.cjs
T
Lauri Ojansivu 29fd503317 Refresh lazy card windows after card changes
Keep FerretDB's bounded card window as a fetched snapshot, but observe the unrestricted indexed selector and diff a fresh window whenever a matching card changes. Publish added, changed and removed DDP messages so remote edits and cross-list moves render without a browser reload. Cover additions, edits, removals, unchanged cards, cleared fields and a forced-lazy browser scenario.

Thanks to hmeunier95 and xet7 !

Fixes #6645,
2026-08-28 17:40:10 +03:00

47 lines
1.4 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const test = require('node:test');
global.EJSON = {
equals(left, right) {
return JSON.stringify(left) === JSON.stringify(right);
},
};
const { diffCardWindow } = require('../models/lib/cardWindowDiff');
test('a refreshed card window reports additions, edits and moves out', () => {
const before = [
{ _id: 'stay', title: 'Old title', listId: 'list-a', sort: 1 },
{ _id: 'move', title: 'Moving', listId: 'list-a', sort: 2 },
];
const after = [
{ _id: 'new', title: 'Moved in', listId: 'list-a', sort: 1 },
{ _id: 'stay', title: 'New title', listId: 'list-a', sort: 2 },
];
assert.deepEqual(diffCardWindow(before, after), {
added: [after[0]],
changed: [{ _id: 'stay', fields: { title: 'New title', sort: 2 } }],
removed: ['move'],
});
});
test('unchanged cards produce no DDP messages', () => {
const card = { _id: 'same', title: 'Same', labels: ['one'] };
assert.deepEqual(diffCardWindow([card], [{ ...card, labels: ['one'] }]), {
added: [], changed: [], removed: [],
});
});
test('removed fields are explicitly cleared on the client', () => {
const diff = diffCardWindow(
[{ _id: 'card', title: 'Card', optional: 'old' }],
[{ _id: 'card', title: 'Card' }],
);
assert.equal(diff.changed.length, 1);
assert.equal(Object.hasOwn(diff.changed[0].fields, 'optional'), true);
assert.equal(diff.changed[0].fields.optional, undefined);
});