mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
One board can be Home: logging in opens it instead of the All Boards page. That has always existed, set from Multi-Selection's "Set as Home board (opened after login)", but there was nowhere that said which board it was - the setting was write-only, and the only way to find out what you had chosen was to log out. Home is now a section of All Boards with a row in the left menu, a home icon and the word Home, a count beside it, and the address /allboards/home. It is the first row when a Home board is set - it is the board this user starts in - and still there, further down, when none is, because the place to drop a board onto has to exist before there is anything in it. Drop a board on the row to make it Home. A drop replaces rather than toggling: Home holds one board, and a drop that sometimes set and sometimes cleared would depend on state the reader cannot see while dragging. Home is a mark on a board, not a place boards are kept - exactly like a star. The board stays in Remaining, or in its workspace, and appears in Home as well; dragging it out of Home onto any other row takes it off Home and leaves it where it lives. That is why the drag carries where it started. The server accepts only a board the caller is a member of and that is not archived, and clears only the board that is actually theirs. Nothing automatic writes it; Sandstorm's auto-open still persists nothing. Documented in docs/Features/Board/Home.md. Thanks to xet7 !
111 lines
4.7 KiB
JavaScript
111 lines
4.7 KiB
JavaScript
'use strict';
|
|
|
|
// Tests for the Sandstorm "open one board on start" decision
|
|
// (models/lib/sandstormAutoOpen.js): saved-default wins, single-board opens+saves,
|
|
// zero/many stays, and everything waits until inputs are ready. Includes negatives.
|
|
//
|
|
// Run: node tests/sandstormAutoOpen.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const { decideSandstormAutoOpen } = require('../models/lib/sandstormAutoOpen.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
test('waits until the grain login (userId) has landed', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: false, boardsReady: true, boardCount: 1, onlyBoardId: 'a' }),
|
|
{ action: 'wait' },
|
|
);
|
|
});
|
|
|
|
test('a saved Home board always wins', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: 'saved1', boardsReady: false }),
|
|
{ action: 'redirect', boardId: 'saved1' },
|
|
);
|
|
// even when there are many boards, the saved choice still wins
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: 'saved1', boardsReady: true, boardCount: 5 }),
|
|
{ action: 'redirect', boardId: 'saved1' },
|
|
);
|
|
});
|
|
|
|
test('waits for the boards subscription before counting', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: null, boardsReady: false, boardCount: 0 }),
|
|
{ action: 'wait' },
|
|
);
|
|
});
|
|
|
|
test('exactly one board -> just open it (NOT saved)', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: null, boardsReady: true, boardCount: 1, onlyBoardId: 'only1' }),
|
|
{ action: 'redirect', boardId: 'only1' },
|
|
);
|
|
});
|
|
|
|
test('many boards + no saved default -> stay on All Boards', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: null, boardsReady: true, boardCount: 3 }),
|
|
{ action: 'stay' },
|
|
);
|
|
});
|
|
|
|
test('zero boards + no saved default -> stay on All Boards (negative: no redirect)', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: null, boardsReady: true, boardCount: 0 }),
|
|
{ action: 'stay' },
|
|
);
|
|
});
|
|
|
|
test('single count but missing id -> stay (never redirect to undefined)', () => {
|
|
assert.deepStrictEqual(
|
|
decideSandstormAutoOpen({ userReady: true, savedDefaultId: null, boardsReady: true, boardCount: 1, onlyBoardId: undefined }),
|
|
{ action: 'stay' },
|
|
);
|
|
});
|
|
|
|
// --- source guards: the feature is wired end-to-end ---
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const repoRoot = path.resolve(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
|
|
|
|
test('router runs the Sandstorm auto-open reactively and only for Sandstorm', () => {
|
|
const r = read('config/router.js');
|
|
assert.ok(/decideSandstormAutoOpen/.test(r), 'uses the pure decision');
|
|
assert.ok(/if \(isSandstorm\)\s*{\s*\n\s*startSandstormAutoOpen\(\)/.test(r), 'gated to Sandstorm');
|
|
assert.ok(/Meteor\.subscribe\('boards'\)/.test(r) && /boardsHandle\.ready\(\)/.test(r), 'waits for boards ready');
|
|
assert.ok(/Tracker\.autorun/.test(r), 'reactive (waits out async grain login)');
|
|
// NEGATIVE guard: auto-open must NOT persist anything (no setDefaultBoard call).
|
|
assert.ok(!/setDefaultBoard/.test(r), 'does not save the single board');
|
|
});
|
|
|
|
test('auto-open persists nothing: nothing on that path saves a Home board', () => {
|
|
// This used to read "the name `setDefaultBoard` appears nowhere", which was a
|
|
// proxy for "there is no unconditional setter" back when the only way to set
|
|
// a Home board was the explicit toggle. There IS one now - dropping a board
|
|
// on the Home row replaces whatever was there (docs/Features/Board/Home.md) -
|
|
// so the guard checks what it was actually protecting: the auto-open path
|
|
// does not save anything. A grain that opens its one board must not thereby
|
|
// decide which board that user starts in.
|
|
assert.ok(!/setDefaultBoard/.test(read('models/lib/sandstormAutoOpen.js')),
|
|
'the decision does not save');
|
|
const users = read('server/models/users.js');
|
|
const at = users.indexOf('async setDefaultBoard(boardId) {');
|
|
assert.notStrictEqual(at, -1, 'the setter is a Meteor method');
|
|
const fn = users.slice(at, users.indexOf('\n },', at));
|
|
// It is reachable only by being CALLED as a method - by a user, about a board
|
|
// they are a member of - which is what keeps it off every automatic path.
|
|
assert.ok(/check\(boardId, String\)/.test(fn), 'it checks its argument');
|
|
assert.ok(/'members\.userId': this\.userId/.test(fn),
|
|
'and only accepts a board the caller can actually open');
|
|
});
|
|
|
|
console.log(`\nAll ${passed} sandstorm-auto-open tests passed`);
|