Files
wekan/tests/defaultBoard.test.cjs
T
Lauri Ojansivu fcfed1fd37 All Boards: Search and Multi-Selection become the board header's controls.
All Boards had a search FIELD in its header bar, and a Multi-Selection button
whose actions were four icons beside it. A board has a search BUTTON and a
Multi-Selection button, and both open the right sidebar. Two pages, the same two
control names in the same place, behaving differently - and one of them not the
way the rest of WeKan does. They are the board's now, and they are the same
markup: headerBarControls.jade holds one headerSearchButton and one
headerMultiSelectionButton, included by the board header of the Swimlanes view
and by the All Boards bar. The two copies had already drifted - the close button
that turns Multi-Selection off said "Clear filter" on the board header, which is
what a different control does, and says multi-selection-off in both now.

Only the markup is shared. What a click does is not - a board searches and
selects cards, All Boards searches and selects boards - and it does not need to
be: a Blaze event map catches events from the templates rendered inside it, so
each bar's own map sees the clicks on its own copy. isActive is passed in,
because the two pages keep different selection objects.

All Boards has a right sidebar of its own. Not the board one: that is built
around a board's members, labels, activities and settings, and this page has no
board. It borrows the SHELL - the same .board-sidebar.sidebar classes, the same
close button, the same title-and-back-arrow above a view - so the two look and
behave alike, and it has three views. home, what the hamburger opens, is the
page's menu: Search, Multi-Selection, and Boards in Archive, which had a handler
in the header bar and no way to reach it. search is the field that was in the
bar, still writing the page's own search term so the boards behind it narrow as
you type. multiselection is where the actions on a selection went - star, home,
archive, duplicate and a way out - each with its name beside it instead of being
a crowded icon. Open/closed and which view are separate, so closing does not
forget where you were, and Escape closes it by KEY only: the click half of
EscapeActions would close it on every click, including clicks inside it.

The bar also gained the divider and the hamburger, in their own flex item and
last in the source exactly as the board header has them, which is what keeps the
hamburger in the top right on a phone while the other buttons wrap.

Two things this turned up. A .jade file is not picked up by being on disk - it
has to be imported from client/features/, and the shared controls threw "No such
template: headerSearchButton" on render until they were; a guard now requires
every .jade under client/components to be imported and every +template it
includes to exist, and it found a dangling +subtaskDeleteDialog that has never
had a template (unreachable, so it has never thrown, and it is recorded with
that reason rather than hidden). And deriving a template name from a view name
gave allBoardsMultiselectionSidebar for allBoardsMultiSelectionSidebar - one
letter, renders nothing, no error worth the name - so the names are an explicit
map the guard checks.

Written down in docs/Design/Page/Search.md and Multi-Selection.md, one per
shared control, each covering both pages, with All-Boards.md pointing at them.

Four guards pinned the previous shape and now pin this one, each saying why it
changed: the search field in the bar, the four selection buttons in the bar, the
Multi-Selection parity check that is structural now that there is one template,
and the home-board action that moved to the sidebar.

Thanks to xet7 !
2026-07-31 07:14:52 +03:00

115 lines
5.0 KiB
JavaScript

'use strict';
// Tests for #2220: mark a board that opens automatically after login.
// Behavioural coverage of the toggle/decision logic (incl. negative cases) plus
// source guards that the feature is wired end-to-end. The model/router code is
// Meteor-coupled, so the behavioural part reimplements the tiny decision the real
// `toggleDefaultBoard`/`isDefaultBoard` make.
//
// Run: node tests/defaultBoard.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
// Mirrors models/users.js: getDefaultBoardId / isDefaultBoard / toggleDefaultBoard.
function makeUser(defaultBoardId) {
return {
profile: defaultBoardId ? { defaultBoardId } : {},
getDefaultBoardId() {
return (this.profile && this.profile.defaultBoardId) || null;
},
isDefaultBoard(boardId) {
return this.getDefaultBoardId() === boardId;
},
// the Mongo update toggleDefaultBoard would apply
toggleUpdate(boardId) {
return this.isDefaultBoard(boardId)
? { $unset: { 'profile.defaultBoardId': '' } }
: { $set: { 'profile.defaultBoardId': boardId } };
},
};
}
test('no default set: nothing is the default, toggling SETS it', () => {
const u = makeUser(null);
assert.strictEqual(u.getDefaultBoardId(), null);
assert.strictEqual(u.isDefaultBoard('a'), false); // negative
assert.deepStrictEqual(u.toggleUpdate('a'), { $set: { 'profile.defaultBoardId': 'a' } });
});
test('default set to A: A is the default, B is NOT', () => {
const u = makeUser('a');
assert.strictEqual(u.getDefaultBoardId(), 'a');
assert.strictEqual(u.isDefaultBoard('a'), true);
assert.strictEqual(u.isDefaultBoard('b'), false); // negative
});
test('toggling the CURRENT default clears it (unset)', () => {
const u = makeUser('a');
assert.deepStrictEqual(u.toggleUpdate('a'), { $unset: { 'profile.defaultBoardId': '' } });
});
test('toggling a DIFFERENT board switches the default to it', () => {
const u = makeUser('a');
assert.deepStrictEqual(u.toggleUpdate('b'), { $set: { 'profile.defaultBoardId': 'b' } });
});
// --- source guards: the feature is wired end-to-end ---
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
test('user model: schema + helpers + toggle exist', () => {
const m = read('models/users.js');
assert.ok(/'profile\.defaultBoardId'/.test(m), 'schema field');
assert.ok(/getDefaultBoardId\(\)/.test(m) && /isDefaultBoard\(boardId\)/.test(m), 'helpers');
assert.ok(/toggleDefaultBoard\(boardId\)/.test(m), 'toggle method');
assert.ok(/\$unset:\s*{\s*'profile\.defaultBoardId'/.test(m), 'toggle clears the current default');
});
test('server method toggleDefaultBoard exists and is auth-guarded', () => {
const s = read('server/models/users.js');
const i = s.indexOf('toggleDefaultBoard(boardId)');
assert.ok(i !== -1, 'server method');
const body = s.slice(i, i + 500);
assert.ok(/not-logged-in/.test(body), 'requires login');
assert.ok(/\$unset|\$set/.test(body), 'sets/unsets the field');
});
test('router redirects to the default board ONCE per session (login), not every visit', () => {
const r = read('config/router.js');
assert.ok(/maybeRedirectToDefaultBoard/.test(r), 'redirect helper');
// NEGATIVE guard: it must be gated by a once-per-session flag, otherwise the
// "All Boards" link could never be reached.
assert.ok(/Session\.get\('defaultBoardRedirectDone'\)/.test(r), 'once-per-session guard');
assert.ok(/getDefaultBoardId\(\)/.test(r) && /FlowRouter\.go\('board'/.test(r), 'redirects to the board');
});
test('the per-TILE Home-board toggle is disabled, but the "Selected:" home action sets it (#2220)', () => {
// Setting a Home board from an individual All Boards tile is intentionally
// disabled (the fa-home per-tile toggle element and its click handler are not
// rendered/wired). Since d67d27f0d, the Home board is instead set from the
// "Selected:" bulk action (js-home-selected), which DOES call toggleDefaultBoard.
const jade = read('client/components/boards/boardsList.jade');
assert.ok(!/a\.js-set-default-board\(/.test(jade), 'no rendered per-tile home-board toggle element');
const js = read('client/components/boards/boardsList.js');
assert.ok(!/'click \.js-set-default-board'/.test(js), 'no per-tile set-default-board click handler');
// The "Selected:" home action is the supported way to set/clear the Home
// board. It is in the All Boards SIDEBAR now - the actions on a selection
// moved there, the way a board puts them in its multi-selection sidebar - so
// this reads the file it lives in rather than the page's.
const sidebar = read('client/components/boards/allBoardsSidebar.js');
assert.ok(/'click \.js-home-selected'/.test(sidebar), 'the "Selected:" home action handler exists');
assert.ok(/Meteor\.call\('toggleDefaultBoard'/.test(sidebar),
'the "Selected:" home action toggles the default board');
});
console.log(`\nAll ${passed} default-board (#2220) tests passed`);