mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A feature's guide now sits under the menu it is used from, read from the templates rather than from where somebody once put it: Header-Bar, All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar (Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists, Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several menus (editor, history, theme, translations, email, troubleshooting) are in General. - Each area has a README mapping its menu entries to their guides and to the template or server module that implements them. Board-Header/README.md lists all 40 Board View entries with the template boardBody.jade renders; five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of their own yet and say so. - Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all of them with their English labels. - Pages keep their file names. Where a released changelog links an old path, a "# Moved" page stays there and points to the new one; test-menu.sh skips folders holding only those. - Undo was filed under Login; it is General/Undo now. - Every link in docs, code comments, scripts and tests follows the move; docsLinksResolve checks them all. Tests that read a doc follow it to its new place. boardViewSettings now fails when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or names a template boardBody.jade does not render. 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/All-Boards/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`);
|