mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Each was checked for which side was wrong: - The LibreJS labels page sent Cache-Control: public; it is private now, as fileCacheHeaders requires of every response. - Closing a card marks it seen (#2111): that code moved below the #6686 popup handling, which labelsPopupStaleCardContext reads from the top of onDestroyed; unreadChanges now finds it anywhere in onDestroyed. - The shared header helper (#2805) moved below the swimlane's currentUser helper, where largeBoardDataLoading pins it. - The Story/Task kind, column set places and drawing strokes (#2012, #211, #1178) get their rule e-mail dispositions: none is e-mail content. - Guards updated for deliberate changes, each saying why: the Rules group in Admin Panel Visibility (#2217), the rule under the team tabs in All Boards (#802, the two around Workspaces still pinned where they are), and a linked list's card clearing the title draft only after it was added (#2809, every clear checked against the add before it). Thanks to xet7 !
37 lines
2.3 KiB
JavaScript
37 lines
2.3 KiB
JavaScript
'use strict';
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
const source = fs.readFileSync('client/components/lists/listBody.js', 'utf8');
|
|
const start = source.indexOf(" this.subscribe('unsaved-edits');", source.indexOf('Template.addCardForm.onCreated'));
|
|
const setup = source.slice(start, source.indexOf(' this.labels = ', start));
|
|
test('draft writes are owned, scoped to list/swimlane/position and cleared only explicitly', () => {
|
|
let owner = 'author'; const writes = [];
|
|
const context = { Meteor: { userId: () => owner }, clearTimeout() {},
|
|
Template: { currentData: () => ({ listId: 'list', swimlaneId: 'lane', position: 'top' }) },
|
|
UnsavedEdits: { set: (key, value) => writes.push({ ...key, value }), reset: key => writes.push({ ...key, cleared: true }) } };
|
|
const tpl = { subscribe() {} };
|
|
vm.runInNewContext(`(function () {${setup}})`, context).call(tpl);
|
|
tpl.saveTitleDraft('Unfinished');
|
|
assert.deepEqual(writes[0], { fieldName: 'newCardTitle:lane:top', docId: 'list', value: 'Unfinished' });
|
|
owner = 'other'; tpl.saveTitleDraft('Must not save'); assert.equal(writes.length, 1);
|
|
owner = null; tpl.saveTitleDraft(''); assert.equal(writes.length, 1);
|
|
owner = 'author'; tpl.saveTitleDraft(''); assert.equal(writes[1].cleared, true);
|
|
});
|
|
test('draft clears after insertion succeeds and flushes on composer teardown', () => {
|
|
// Every clear follows a card that was really added. #2809 added a second way
|
|
// to add one - a linked list's card goes to its source list through
|
|
// addCardToLinkedList - so each clear is checked against the add before it,
|
|
// not only the first clear against Cards.insertAsync.
|
|
const clears = [...source.matchAll(/formComponent\.saveTitleDraft\(/g)].map(m => m.index);
|
|
assert.ok(clears.length >= 2);
|
|
for (const at of clears) {
|
|
const before = source.slice(Math.max(0, at - 200), at);
|
|
assert.match(before, /(const _id = await Cards\.insertAsync\(cardFields\)|await Meteor\.callAsync\('addCardToLinkedList', data\._id, title\));\s*titleIndex \+= 1;\s*$/,
|
|
'the draft is cleared only after the card was added');
|
|
}
|
|
assert.match(source, /Template.addCardForm.onDestroyed[\s\S]*?titleDraftPending !== undefined[\s\S]*?saveTitleDraft/);
|
|
assert.match(source, /titleDraftEdited\) return/);
|
|
});
|