Files
wekan/tests/foldSections.test.cjs
T
Lauri Ojansivu cff80a9d7b Make showing dependencies each user's own choice, and add My Dependencies.
Issue #6732: the board-header "Show dependencies" button wrote one shared
board field, so one user turning the lines on or off did it for everybody,
and only board admins could write that field, so a member - or anyone on a
public board - who could see the board could not turn them on at all.

The button is gone from the header. At the top of Member Settings are now:

- Show My Dependencies
- Show Board Dependencies
- Import
- Export

Both switches are off by default and saved in the user's profile, so each
user decides for themselves and anyone who can view a board may show its
dependencies.

Board Dependencies stay on the board's cards. They may now be edited by
every role that can edit OR move cards - a Worker included - and by an
assigned-only member on the cards assigned to them; one rule
(models/lib/dependencyAccess.js) is applied by new server methods, by the
card details, the line popup, drawing on the board, Import and the REST
routes. My Dependencies are a new layer in the user's profile: each user's
own lines between cards they can see, drawn dashed and seen only by them.
The client cannot write them directly; only the methods, which check card
access, can.

Import and Export work on the open board in the Board Settings / Export
formats (JSON, and SVG that re-imports). Importing Board Dependencies is
offered only to roles that may edit or move cards, and every import now
combines: a line already there is kept exactly as it is, and only missing
lines are added - also for All Boards / Import / Dependencies, which used to
overwrite an existing line's type and colour. The design is written up in
docs/Features/Editor/RedStrings/Board-And-My-Dependencies.md.

Tests: the role table, viewing, assigned-only scope, normalizing and
combining (unit), with guards that the header toggle and every reader of
the old board flag are gone and every write goes through the rule; a
full-app test drives the methods as admin, Worker, read-only, assigned-only
and a stranger; Playwright covers the menu order and defaults, a per-user
switch that leaves another member's view alone, a read-only member's My
Dependencies (dashed, unseen by the owner) with import and export, and a
Worker's combining board import - in Chromium and WebKit. Header, fold and
mobile guards that listed the old button are updated. 567 server tests pass.

Thanks to nalilord and xet7 !

Fixes #6732.
2026-10-01 19:18:58 +03:00

165 lines
8.2 KiB
JavaScript

'use strict';
// The board's chrome folds: the sidebar's sections, and the header's controls.
// Run: node tests/foldSections.test.cjs
//
// Activities got a caret first, replacing an eye and the words "Show
// activities" beside it. Members and Labels are the two sections above it, and
// they had no way to fold at all: the People / Organizations / Teams / Domains
// tabs with their avatars, and every label of the board, were always open and
// pushed everything below them down the panel.
//
// They fold now, by the same control an opened card's sections use: the heading
// is the button, a caret in front of it says which way it is, and clicking it
// hides what belongs to that heading.
//
// Activities is deliberately NOT in the shared store: it has a board setting of
// its own (`board.showActivities`) that also decides what the publication
// sends, so its caret writes that instead. Members and Labels decide nothing on
// the server, so they are a per-session choice of the reader's.
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 jade = read('client/components/sidebar/sidebar.jade');
const js = read('client/components/sidebar/sidebar.js');
const css = read('client/components/sidebar/sidebar.css');
const state = read('client/lib/foldState.js');
const headerJade = read('client/components/boards/boardHeader.jade');
const headerJs = read('client/components/boards/boardHeader.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('foldSections:');
const members = jade.slice(jade.indexOf('template(name="membersWidget")'),
jade.indexOf('template(name="boardOrgGeneral")'));
const labels = jade.slice(jade.indexOf('template(name="labelsWidget")'),
jade.indexOf('template(name="memberPopup")'));
test('Members has a caret at the start of its heading', () => {
assert.ok(/h3\.js-toggle-fold\(data-fold="members"/.test(members),
'the heading is the button');
assert.ok(/i\.fa\(class="\{\{foldCaret 'members'\}\}"\)/.test(members),
'with a caret drawn from the section state');
assert.ok(members.indexOf('foldCaret') < members.indexOf('fa-users'),
'at the LEFT of the members icon, before the name');
});
test('folding Members hides the tabs and the avatars in them', () => {
assert.ok(/if isFoldOpen 'members'\n\s+\+basicTabs\(tabs=tabs\)/.test(members),
'the whole tab strip is inside the fold');
// The avatars live in the tab contents, so they go with it; this pins that
// they are still INSIDE basicTabs and not left behind beside it.
const open = members.slice(members.indexOf("if isFoldOpen 'members'"));
assert.ok(open.indexOf('+basicTabs') < open.indexOf('+userAvatar'),
'the avatars are under the tabs, which are under the fold');
});
test('Labels has the same caret, and folds its labels', () => {
assert.ok(/h3\.js-toggle-fold\(data-fold="labels"/.test(labels),
'the heading is the button');
assert.ok(labels.indexOf('foldCaret') < labels.indexOf('fa-tag'),
'the caret comes before the tag icon');
assert.ok(/if isFoldOpen 'labels'\n\s+\.board-widget-content/.test(labels),
'the labels under the heading are inside the fold');
assert.ok(/\.board-widget-content\n\s+each currentBoard\.labels/.test(labels),
'and they are still INSIDE that content box, not siblings of it');
assert.ok(/if currentUser\.isBoardAdmin\n\s+a\.card-label\.add-label\.js-add-label/.test(labels),
'so is the + that creates one');
});
test('one handler, one rule, for both headings', () => {
assert.ok(/'click \.js-toggle-fold'\(event\)/.test(js), 'a click folds');
assert.ok(/'keydown \.js-toggle-fold'\(event\)/.test(js),
'and Enter or Space does the same - the heading says role="button"');
assert.ok(/event\.key !== 'Enter' && event\.key !== ' '/.test(js), 'only those two keys');
assert.ok(/toggleFold\(event\.currentTarget\.dataset\.fold\)/.test(js),
'the section names itself in the markup');
assert.ok(/h3\.js-toggle-fold \{[^}]*cursor: pointer/.test(css),
'and a mouse sees a button');
});
test('an unknown section is OPEN, not hidden (negative)', () => {
// A section added later must show up rather than disappear because nobody
// ever wrote a `true` for it.
assert.ok(/state === undefined \? true : state/.test(state), 'default open');
assert.ok(/caretClassFor/.test(state),
'and the caret comes from the shared rule, so it points the same way as a card\'s');
});
test('the choice is the reader\'s, and is not a board setting (negative)', () => {
// Members and Labels decide nothing on the server: folding them must not
// write to the board, where it would fold for everybody.
assert.ok(/new ReactiveDict\(\)/.test(state), 'module-level, per session');
assert.ok(!/Boards\.update|Meteor\.call/.test(state), 'nothing is stored on the board');
// Activities is the opposite, and stays where it is.
assert.ok(/toggleShowActivities\(\)/.test(js),
'Activities still writes its own board setting, which the publication reads');
assert.ok(/showActivities/.test(state),
'and the module says why it is not one of these');
});
// ── the first header bar's board controls ──────────────────────────────────
const controls = headerJade.slice(headerJade.indexOf('template(name="boardHeaderButtons")'),
headerJade.indexOf('template(name="boardVisibilityList")'));
test('a caret leads the board controls, before the lock', () => {
assert.ok(/a\.board-header-btn\.js-toggle-fold\(data-fold="board-controls"/.test(controls),
'a button of its own, in the same bar');
assert.ok(controls.indexOf('js-toggle-fold') < controls.indexOf('js-change-visibility'),
'at the start of the group - left of the lock in a left-to-right page');
assert.ok(/i\.fa\(class="\{\{foldCaret 'board-controls'\}\}"\)/.test(controls),
'and it is the same caret, so it mirrors in RTL by itself');
});
// #6732: Show dependencies left this bar for Member Settings, so six remain.
test('folding hides the six controls it was asked to hide', () => {
const folded = ['js-change-visibility', 'js-watch-board', 'js-sort-cards',
'js-open-filter-view', 'js-open-search-view',
'js-multiselection-activate'];
for (const control of folded) {
const at = controls.indexOf(control);
assert.ok(at !== -1, `${control} is in the bar`);
const before = controls.lastIndexOf("if isFoldOpen 'board-controls'", at);
assert.ok(before !== -1, `${control} is inside the fold`);
}
});
test('a board\'s own Rules buttons are NOT folded away (negative)', () => {
// Somebody added those to this board on purpose; they are not part of the
// standard control set the caret hides.
const at = controls.indexOf('+boardButtons');
assert.ok(at !== -1, 'the rule buttons are still there');
const line = controls.slice(controls.lastIndexOf('\n', at) + 1, at + 14);
assert.strictEqual(line.trim(), '+boardButtons');
assert.strictEqual(line.length - line.trimStart().length, 8,
'at the group\'s own indentation, outside both fold blocks');
});
test('the caret is named by words the app already has (negative)', () => {
assert.ok(/\{\{_ 'collapse'\}\}/.test(controls) && /\{\{_ 'uncollapse'\}\}/.test(controls),
'Collapse and Uncollapse, so no new key in 147 language files');
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
assert.ok(en.collapse && en.uncollapse, 'and both exist');
assert.ok(!en['board-header-controls'], 'no key was invented for it');
});
test('the header has its own handler, on the same class', () => {
// A Blaze event map only sees its own template: the sidebar's handler cannot
// catch a click in the header bar.
assert.ok(/'click \.js-toggle-fold'\(event\)/.test(headerJs), 'a click folds');
assert.ok(/'keydown \.js-toggle-fold'\(event\)/.test(headerJs), 'and so do Enter and Space');
assert.ok(/toggleFold\(event\.currentTarget\.dataset\.fold\)/.test(headerJs),
'through the same store as the sidebar');
assert.ok(/role="button" tabindex="0"/.test(controls), 'and the caret says it is a button');
});
console.log(`\nfoldSections: ${passed} tests passed`);