mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
138 lines
6.2 KiB
JavaScript
138 lines
6.2 KiB
JavaScript
'use strict';
|
|
|
|
// The "Selected: ★" button on All Boards is a TOGGLE over the whole selection.
|
|
//
|
|
// It only ever added stars: it walked the selection and starred whatever was
|
|
// not starred yet. So once every selected board was starred the button did
|
|
// nothing at all - clicking it again could not undo what it had just done - and
|
|
// its tooltip said "Star the selected boards" whatever state the selection was
|
|
// in.
|
|
//
|
|
// Run: node tests/selectedStars.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
|
|
|
const {
|
|
SELECTED_STAR_STAR, SELECTED_STAR_UNSTAR,
|
|
selectedStarAction, selectedStarTitleKey,
|
|
} = require('../models/lib/selectedStars');
|
|
|
|
// A selection where the boards named in `starred` are starred.
|
|
const act = (ids, starred = []) =>
|
|
selectedStarAction(ids, id => starred.includes(id));
|
|
|
|
let passed = 0;
|
|
const tests = [];
|
|
function test(name, fn) { tests.push([name, fn]); }
|
|
|
|
console.log('selectedStars:');
|
|
|
|
test('none starred: star every one of them', () => {
|
|
const r = act(['a', 'b', 'c']);
|
|
assert.strictEqual(r.action, SELECTED_STAR_STAR);
|
|
assert.deepStrictEqual(r.boardIds, ['a', 'b', 'c']);
|
|
});
|
|
|
|
test('all starred: UNSTAR every one of them', () => {
|
|
// This is the case that did nothing before.
|
|
const r = act(['a', 'b', 'c'], ['a', 'b', 'c']);
|
|
assert.strictEqual(r.action, SELECTED_STAR_UNSTAR);
|
|
assert.deepStrictEqual(r.boardIds, ['a', 'b', 'c']);
|
|
});
|
|
|
|
test('some starred: star the REST, and touch nothing else', () => {
|
|
const r = act(['a', 'b', 'c', 'd'], ['b', 'd']);
|
|
assert.strictEqual(r.action, SELECTED_STAR_STAR, 'the action is still star');
|
|
// Only the unstarred ones: the ids returned are the ones to TOGGLE, and
|
|
// toggling an already-starred board would un-star it. A click that starred
|
|
// two boards and un-starred two others is not something a button may do.
|
|
assert.deepStrictEqual(r.boardIds, ['a', 'c']);
|
|
});
|
|
|
|
test('one board on its own toggles both ways', () => {
|
|
assert.deepStrictEqual(act(['a']), { action: SELECTED_STAR_STAR, boardIds: ['a'] });
|
|
assert.deepStrictEqual(act(['a'], ['a']), { action: SELECTED_STAR_UNSTAR, boardIds: ['a'] });
|
|
});
|
|
|
|
test('and starring twice is idempotent, which is the point', () => {
|
|
// Click once from nothing-starred, and everything is starred; the second
|
|
// click is the undo. Before, the second click was a no-op.
|
|
const first = act(['a', 'b']);
|
|
const after = first.boardIds; // now starred
|
|
const second = act(['a', 'b'], after);
|
|
assert.strictEqual(second.action, SELECTED_STAR_UNSTAR);
|
|
assert.deepStrictEqual(second.boardIds, ['a', 'b']);
|
|
const third = act(['a', 'b'], []); // and back again
|
|
assert.strictEqual(third.action, SELECTED_STAR_STAR);
|
|
});
|
|
|
|
test('an empty or junk selection is answered, not thrown on (negative)', () => {
|
|
for (const empty of [[], null, undefined, 'nonsense', 42]) {
|
|
const r = selectedStarAction(empty, () => true);
|
|
assert.strictEqual(r.action, SELECTED_STAR_STAR, `${JSON.stringify(empty)} is harmless`);
|
|
assert.deepStrictEqual(r.boardIds, []);
|
|
}
|
|
// A hole in the list is not a board.
|
|
assert.deepStrictEqual(act([null, 'a', undefined, ''], []).boardIds, ['a']);
|
|
});
|
|
|
|
test('the tooltip names the direction the button goes', () => {
|
|
assert.strictEqual(selectedStarTitleKey(SELECTED_STAR_STAR), 'set-selected-starred');
|
|
assert.strictEqual(selectedStarTitleKey(SELECTED_STAR_UNSTAR), 'set-selected-unstarred');
|
|
// Anything unexpected reads as "star", the safer of the two to offer.
|
|
assert.strictEqual(selectedStarTitleKey(undefined), 'set-selected-starred');
|
|
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
assert.strictEqual(en['set-selected-starred'], 'Star the selected boards');
|
|
assert.strictEqual(en['set-selected-unstarred'], 'Unstar the selected boards');
|
|
});
|
|
|
|
test('every language file has the new keys, so none of them loses a tooltip', () => {
|
|
// Untranslated everywhere means the English source stands in as a
|
|
// placeholder, which is what CLAUDE.md's translation policy says happens -
|
|
// but the KEY has to exist in every file or that language shows nothing.
|
|
const dir = path.join(ROOT, 'imports/i18n/data');
|
|
const files = fs.readdirSync(dir).filter(f => f.endsWith('.i18n.json'));
|
|
assert.ok(files.length > 100, 'all the language files');
|
|
const missing = files.filter(f => {
|
|
const obj = JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8'));
|
|
return !('set-selected-unstarred' in obj) || !('multi-selection-off' in obj);
|
|
});
|
|
assert.deepStrictEqual(missing, [], `missing in: ${missing.join(', ')}`);
|
|
});
|
|
|
|
test('the click and the label ask the same function', () => {
|
|
// Two copies of "which way does this button go" would be two answers to it,
|
|
// and the label would eventually lie about what the click does.
|
|
//
|
|
// The star action lives in the All Boards SIDEBAR now, with the rest of the
|
|
// actions on a selection - it was a header-bar button with a tooltip, and it
|
|
// is a sidebar row with its name written beside it.
|
|
const js = read('client/components/boards/allBoardsSidebar.js');
|
|
assert.ok(/function currentSelectedStarAction\(\)/.test(js), 'one function decides');
|
|
assert.ok(/currentSelectedStarAction\(\)\.boardIds\.forEach/.test(js),
|
|
'the click toggles exactly the boards it names');
|
|
assert.ok(/selectedStarTitleKey\(currentSelectedStarAction\(\)\.action\)/.test(js),
|
|
'and the label reads the same answer');
|
|
|
|
// And the click no longer decides for itself which boards to skip.
|
|
const handler = js.slice(js.indexOf("'click .js-star-selected'"));
|
|
const body = handler.slice(0, handler.indexOf('\n },'));
|
|
assert.ok(!/hasStarred/.test(body), 'the handler must not re-derive the rule');
|
|
|
|
const jade = read('client/components/boards/allBoardsSidebar.jade');
|
|
assert.ok(/span \{\{selectedStarTitle\}\}/.test(jade),
|
|
'the star row takes its name from the helper, not a fixed string');
|
|
});
|
|
|
|
for (const [name, fn] of tests) {
|
|
try { fn(); passed++; console.log(' ok -', name); }
|
|
catch (err) { console.error(` FAIL - ${name}\n ${err.message}`); process.exitCode = 1; }
|
|
}
|
|
console.log(`\nselectedStars: ${passed} tests passed`);
|