Files
wekan/tests/boardQueryNavigation.test.cjs
T
Lauri Ojansivu 4387185002 Large board: open and close a card by its address without re-creating the board.
The card and board routes rendered the board layout on every navigation, and
flow-router-extra re-creates the layout each time: every swimlane, list and
minicard was torn down and built again for a card link, the up/down card
keys, back/forward, and closing a card opened from a link. The router now
remembers which board the layout is mounted for (models/lib/boardLayoutMount.js)
and the card and board routes reuse it; the board already follows Session.
Another board, a first load and the list/swimlane routes still render.

tests/playwright/specs/large-board-card-open.e2e.js checks in Chromium,
Firefox and WebKit that a minicard element survives a card opened and closed
by its address, and counts the Tracker work of a click open and close.

Thanks to markusst1982 and xet7 !

Fixes #6745.
2026-10-07 03:08:48 +03:00

54 lines
3.1 KiB
JavaScript

"use strict";
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const { mountedBoardAfterEnter, mustRenderBoardLayout } = require('../models/lib/boardLayoutMount.js');
const source = fs.readFileSync(path.join(__dirname, '../config/router.js'), 'utf8');
const start = source.indexOf("FlowRouter.route('/b/:id/:slug', {");
const end = source.indexOf("\nFlowRouter.route('/shortcuts'", start);
const routeSource = source.slice(start, end);
const helperStart = source.indexOf('function renderBoardLayout(ctx, boardId, routeName) {');
const helperSource = source.slice(helperStart, source.indexOf('\n}\n', helperStart) + 2);
// #6745: whether the board is re-rendered no longer depends on the previous
// PATH but on which board the layout is mounted for (models/lib/boardLayoutMount.js):
// the route that was left decides it, through FlowRouter.triggers.enter.
// `previousRoute` is that route's name, or undefined on a first page load.
function navigate(previousBoard, previousRoute, id) {
const state = { currentBoard: previousBoard };
let action, renders = 0, resets = 0;
const context = {
mustRenderBoardLayout,
mountedBoardId: previousRoute ? mountedBoardAfterEnter(previousBoard, previousRoute) : null,
Session: { get: key => state[key], set: (key, value) => { state[key] = value; } },
FlowRouter: { route: (_, options) => { action = options.action; }, current: () => ({ path: `/b/${id}/board` }) },
EscapeActions: { executeAll() {}, executeUpTo() {} },
Filter: { resetBoardScoped() { resets++; } },
Utils: { manageCustomUI() {}, manageMatomo() {} },
};
vm.runInNewContext(`${helperSource}\n${routeSource}`, context);
// Entering the board route itself keeps whatever was mounted.
context.mountedBoardId = mountedBoardAfterEnter(context.mountedBoardId, 'board');
action.call({ render(layout, data) {
assert.equal(layout, 'defaultLayout'); assert.equal(data.content, 'board'); renders++;
} }, { id });
return { renders, resets, state, mounted: context.mountedBoardId };
}
// setQueryParams reruns the route on the same board: no re-render, filters kept.
assert.equal(navigate('a', 'board', 'a').renders, 0);
assert.equal(navigate('a', 'board', 'a').resets, 0);
// First load renders.
assert.equal(navigate(undefined, undefined, 'a').renders, 1);
// Coming back from a page that is not the board (rules) renders.
assert.equal(navigate('a', 'rules', 'a').renders, 1);
// #6745: closing a card goes card -> board on the SAME board. This used to
// render (every minicard re-created, seconds on a large board); the board on
// screen is now kept, and closing follows Session like opening does.
assert.equal(navigate('a', 'card', 'a').renders, 0);
// A renamed board (old slug -> new slug) is still the same mounted board.
assert.equal(navigate('a', 'board', 'a').mounted, 'a');
const other = navigate('a', 'board', 'b');
assert.equal(other.renders, 1); assert.equal(other.resets, 1); assert.equal(other.state.currentBoard, 'b');
assert.equal(other.mounted, 'b');
console.log('board query navigation: 9 passed');