mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Board View / Timeline (Step 1 of the maintainer's spec): a new menu entry
right after Time, wired end to end like every other view - the
boardChangeViewPopup entry, Utils.setBoardView('board-view-timeline'), an
isViewTimeline() helper and boardBody.jade branch, the two client/lib/utils.js
whitelist arrays, the profile.boardView schema allowedValues, a tooltip-name-
map entry, and template/stylesheet registration in client/features/boards.js.
The view renders a horizontal row of clickable markers built from the
board's distinct activity timestamps (sampled to 50 when there are more),
plus a "Now" marker for the live board. Clicking a marker calls the already-
built, already-tested models/lib/boardTimeline.js's pure
reconstructBoardStateAt(cards, activities, timestamp) - this file does not
reimplement history reconstruction - and renders the result read-only,
grouped by reconstructed list: title, description snippet, labels, members,
due date and an archived badge.
Step 2: each card in a historical view gets a "Restore to this state"
button. It applies the RECONSTRUCTED field values to the card's CURRENT
document by calling only the card's own existing setters one at a time
(setTitle, setDescription, move, addLabel/removeLabel, assignMember/
unassignMember, setDue) - never a bulk update that bypasses them - so each
write is logged as its own Activity by the existing hooks and the restore
itself becomes new, fully visible history. Nothing is deleted. A
confirmation popup (Popup.afterConfirm, the same pattern used elsewhere)
gates the action since it changes the board's current state.
Deliberately deferred, per the task's own scope discipline: "selective
per-member change removal within a time period" is a separate, higher-risk
mutation feature left for a dedicated future pass.
tests/boardViewMenu.test.cjs's VIEWS table gets the new entry (icon
fa-history, template timelineView, helper isViewTimeline) and its HR_AFTER
separator moves from Time to Timeline. tests/boardTimelineRestore.test.cjs
pins that the restore path only calls the card's own setters (with a
negative test scanning for a direct Cards.update/updateAsync bypass), that
the restore button only renders while viewing a historical timestamp, and
that a confirmation step is required before restoring.
Added "Timeline" and its five other UI strings to en.i18n.json and to every
other locale file with real per-language translations (not English
placeholders); verified with fill-translations.mjs --missing.
Thanks to xet7 !
96 lines
5.0 KiB
JavaScript
96 lines
5.0 KiB
JavaScript
'use strict';
|
|
|
|
// Regression coverage for Board View / Timeline's "restore this card to this
|
|
// point in time" action (client/components/boards/timelineView.js), Step 2
|
|
// of the maintainer's spec:
|
|
//
|
|
// "have possibility to restore from any historical status to copy it to
|
|
// newest status. have checks that all data stays at undo history, so that
|
|
// this does not delete any data."
|
|
//
|
|
// Deliberately NOT covered here (explicitly deferred, per the task's scope
|
|
// discipline): "selective per-member change removal within a time period" -
|
|
// that is a separate, higher-risk mutation feature left for a dedicated
|
|
// future pass.
|
|
//
|
|
// Run: node tests/boardTimelineRestore.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const root = path.join(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(root, rel), 'utf8');
|
|
|
|
const timelineJs = read('client/components/boards/timelineView.js');
|
|
const timelineJade = read('client/components/boards/timelineView.jade');
|
|
|
|
test('restoreCardFromTimeline only calls the card\'s OWN existing setters', () => {
|
|
// Every field write goes through a method already used elsewhere in the
|
|
// codebase (setTitle, setDescription, move, addLabel/removeLabel,
|
|
// assignMember/unassignMember, setDue) - never a bulk update.
|
|
const fnStart = timelineJs.indexOf('export async function restoreCardFromTimeline');
|
|
assert.ok(fnStart !== -1, 'restoreCardFromTimeline is exported');
|
|
const fnEnd = timelineJs.indexOf('\n}', fnStart);
|
|
const body = timelineJs.slice(fnStart, fnEnd);
|
|
|
|
['card.setTitle(', 'card.setDescription(', 'card.move(', 'card.addLabel(',
|
|
'card.removeLabel(', 'card.assignMember(', 'card.unassignMember(', 'card.setDue(']
|
|
.forEach(call => assert.ok(body.includes(call), `calls ${call}`));
|
|
});
|
|
|
|
test('negative: the restore function never bypasses the setters with a direct Cards update', () => {
|
|
// Search the WHOLE file (not just the function) for the shape of a bypass -
|
|
// a direct write to the Cards collection - so the guarantee holds even if
|
|
// the function is refactored or another helper is added beside it later.
|
|
assert.doesNotMatch(timelineJs, /Cards\.update(Async)?\s*\(/,
|
|
'timelineView.js never calls Cards.update/updateAsync directly (negative)');
|
|
assert.doesNotMatch(timelineJs, /\$set\s*:/,
|
|
'timelineView.js never builds a raw $set bulk-update document (negative)');
|
|
});
|
|
|
|
test('restoreCardFromTimeline looks up the CURRENT card by id before writing anything', () => {
|
|
const fnStart = timelineJs.indexOf('export async function restoreCardFromTimeline');
|
|
const fnEnd = timelineJs.indexOf('\n}', fnStart);
|
|
const body = timelineJs.slice(fnStart, fnEnd);
|
|
assert.match(body, /ReactiveCache\.getCard\(cardId\)/,
|
|
'reads the live card via ReactiveCache, not a snapshot');
|
|
});
|
|
|
|
test('the restore button is only offered while viewing a historical timestamp', () => {
|
|
// Step 1 (live board) must stay read-only-by-default: the button only
|
|
// renders inside the "if selectedTimestamp" branch, not unconditionally.
|
|
const idx = timelineJade.indexOf('js-restore-card-timeline');
|
|
assert.ok(idx !== -1, 'the restore button exists in the template');
|
|
const before = timelineJade.slice(0, idx);
|
|
assert.ok(before.lastIndexOf('if selectedTimestamp') > before.lastIndexOf('each this.cards'),
|
|
'the restore button is gated behind "if selectedTimestamp"');
|
|
});
|
|
|
|
test('a confirmation step is required before restoring - the click goes through Popup.afterConfirm', () => {
|
|
assert.match(timelineJs, /'click \.js-restore-card-timeline':\s*Popup\.afterConfirm\(\s*'cardRestoreToTimeline'/,
|
|
'the restore click handler is wrapped in Popup.afterConfirm');
|
|
// And the matching confirmation popup template exists with a real confirm
|
|
// button (client/components/main/popup.js's "click .js-confirm" pattern).
|
|
assert.match(timelineJade, /template\(name="cardRestoreToTimelinePopup"\)/,
|
|
'the cardRestoreToTimelinePopup template exists');
|
|
const popupStart = timelineJade.indexOf('template(name="cardRestoreToTimelinePopup")');
|
|
const popupBlock = timelineJade.slice(popupStart, popupStart + 400);
|
|
assert.match(popupBlock, /button\.js-confirm/, 'the popup has a .js-confirm button');
|
|
});
|
|
|
|
test('restoring reuses the exact reconstructed field values, not the live card\'s', () => {
|
|
// The click handler must pass the reconstructed `fields` object captured on
|
|
// the per-card data context, not re-derive values from the live card.
|
|
const idx = timelineJs.indexOf("Popup.afterConfirm('cardRestoreToTimeline'");
|
|
assert.ok(idx !== -1);
|
|
const block = timelineJs.slice(idx, idx + 300);
|
|
assert.match(block, /restoreCardFromTimeline\(cardContext\.cardId, cardContext\.fields\)/);
|
|
});
|
|
|
|
test('the view calls the pure reconstructBoardStateAt() from boardTimeline.js rather than reimplementing it', () => {
|
|
assert.match(timelineJs, /import \{ reconstructBoardStateAt \} from '\/models\/lib\/boardTimeline'/);
|
|
assert.match(timelineJs, /reconstructBoardStateAt\(cards, activities, selected\)/);
|
|
});
|