Files
wekan/tests/mobileModeConsistency.test.cjs
T
Lauri Ojansivu f62258b5cb Header bar: one star group, named view menus, and a Filter button that shuts.
The bar drew TWO stars in a row - one on the starred-boards dropdown and one
for the board you are on - which reads as a single control somehow drawn
twice. The dropdown has no star now: it is a caret and the COUNT of starred
boards, which is what it is about, and the count is shown even at zero
because it is the button's only label and a bare caret says nothing about
what it opens.

The board's own star sits immediately beside it, and the two are wrapped in a
rounded outline of their own, shaped like the phone/desktop toggle's but
WHITE where that one is black: the toggle is a white box sitting on the bar,
so a dark border shows against it, while these buttons sit on the bar's own
colour and need a light one. Without an outline the two read as unrelated
icons that happen to be adjacent - which is what made the two stars confusing
in the first place.

The star is its own template so the bar can place it here rather than among
the board's other controls further along. A Blaze event map only sees events
inside its own template, so its helpers and its click came with its markup,
and the copies left behind in boardHeaderButtons are gone.

The two view menus and Multi-Selection carry their name beside the icon
again. I had made them icon-only earlier and xet7 asked for the words back;
that is the better call - six view glyphs are six things to learn, a
check-box outline says nothing about multi-selection, and a tooltip is the
one place a name cannot be read without hovering. The bar wraps to a second
row when it runs out of width, which is what makes the word affordable now
and did not before. Sort, Search and Boards in Archive stay icons: those
glyphs are well known. A label does not wrap mid-button - two lines inside a
one-line button is worse than the tooltip was.

Clicking Filter while the filter sidebar is already showing closes it. It
only ever opened, so a second click did nothing visible and the only way back
was the sidebar's own X, somewhere else on screen from the thing you just
clicked. Not while a filter is ON, though: the sidebar is then the one place
that says WHAT is being hidden from the board, and closing it would leave a
board showing a subset of its cards with nothing on screen to say so - so it
stays open, and the X beside the button is what clears the filter.
"Showing the filter" is open AND on that view, because a sidebar open on
Activities is not showing the filter and clicking Filter there has to switch
to it rather than close the panel.

models/lib/filterButton.js holds that rule so "which way does this click go"
is answered once, and the guard checks all four combinations without a DOM.

tests/mobileModeConsistency stopped expecting js-star-board among the board
header buttons and says where it went instead; tests/headerBars pins the
group, its light-against-the-bar outline, the labels, and the filter toggle.

Thanks to xet7 !
2026-08-01 00:33:13 +03:00

123 lines
6.6 KiB
JavaScript

'use strict';
// Mobile mode must look the same on a phone and in mobile mode on a desktop window.
//
// Reported with two screenshots of the same app: on an iPhone 12 mini the second
// header bar held a handful of icons and no board title, while a desktop Firefox
// window in mobile mode showed the title and the full set of buttons. Same mode, two
// different bars.
//
// Mobile layout is driven from three switches that did not agree:
// 1. `body.mobile-mode` - the explicit toggle
// 2. `Utils.isMiniScreen()` - which branch of the templates renders (fixed in
// tests/mobileModeFullWidth.test.cjs, where an explicit choice now wins)
// 3. `@media (max-width: 800px)` - the viewport, true on a phone and false on a
// wide desktop window even when mobile mode is on
//
// A rule keyed off one of them that assumes another cannot hold on both devices.
//
// Run: node tests/mobileModeConsistency.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); }
const root = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(root, rel), 'utf8');
const boardCss = read('client/components/boards/boardHeader.css');
const headerCss = read('client/components/main/header.css');
const boardJade = read('client/components/boards/boardHeader.jade');
const listJade = read('client/components/lists/listHeader.jade');
console.log('mobileModeConsistency:');
test('the header buttons are written ONCE, for both screens', () => {
// edit title / visibility / watch / star / sort used to be rendered in exactly
// one of two groups - left `unless isMiniScreen`, right `if isMiniScreen` -
// because a row of LABELLED buttons does not fit on a phone. Whether the two
// switches agreed was the thing this test guarded: hiding the left group in
// mobile mode was a no-op while they did, and deleted five buttons when they
// did not.
//
// There is one copy now. The buttons are icons in the first header bar, named
// by tooltips, and icons fit at both sizes - so the duplication that made the
// two switches able to disagree is gone rather than kept in step.
assert.ok(!/unless isMiniScreen/.test(boardJade), 'no wide-screen-only copy');
assert.ok(!/if isMiniScreen/.test(boardJade), 'and no phone-only copy');
assert.ok(!/\.mobile-mode \.board-header-btns\.left \{[^}]*display:\s*none/.test(boardCss),
'and nothing hides a group that no longer exists');
// Each control appears exactly once IN THE HEADER BUTTONS. The popups below
// mention some of the same classes - `js-change-visibility` is also the link
// inside the visibility popup - so this reads the one template, not the file.
const buttons = boardJade.slice(boardJade.indexOf('template(name="boardHeaderButtons")'),
boardJade.indexOf('template(name="boardVisibilityList")'));
// js-star-board is NOT here any more: the star moved to its own template so
// the first header bar can place it beside the starred-boards dropdown - the
// count of starred boards and whether this is one of them are a pair.
// tests/headerBars.test.cjs checks it there.
for (const control of ['js-change-visibility', 'js-watch-board',
'js-sort-cards', 'js-open-filter-view', 'js-open-search-view',
'js-toggle-dependencies', 'js-multiselection-activate']) {
assert.strictEqual((buttons.match(new RegExp(control, 'g')) || []).length, 1,
`${control} must be written exactly once`);
}
});
test('the second header bar can grow to a second row on a phone', () => {
// The phone block gives the bar a bigger touch target (#6419). As a fixed `height`
// that CLIPPED the second row the bar wraps to when title + buttons do not fit, so
// part of the bar was simply not there.
const phone = headerCss.slice(headerCss.indexOf('@media screen and (max-width: 800px),'));
const bar = /#header #header-main-bar \{([^}]*)\}/.exec(phone);
assert.ok(bar, 'the phone block must still size the bar');
assert.ok(/min-height:\s*48px/.test(bar[1]), 'a floor, so the touch targets stay');
assert.ok(!/[^-]height:\s*48px/.test(bar[1]), 'but not a fixed height, which clips');
});
test('the list title shows whichever markup rendered it', () => {
// listHeader.jade has two shapes: on a mini screen the h2 is a direct child of
// .list-header, otherwise it is wrapped in a div. Mobile mode places the title by
// grid row/column, which only applies to a direct grid ITEM - inside the wrapper
// the placement was ignored and the title was squeezed into the 30px first column.
const mini = listJade.indexOf('if isMiniScreen');
assert.ok(mini > -1, 'the mini-screen branch exists');
assert.ok(/div\(class="\{\{#if collapsed\}\}list-rotated/.test(listJade),
'and the other branch wraps the title in a div');
const rule = /\.mobile-mode \.list-header > div:not\(\.list-rotated\)[^{]*\{([^}]*)\}/
.exec(boardCss);
assert.ok(rule, 'the wrapper must be dropped from the layout in mobile mode');
assert.ok(/display:\s*contents/.test(rule[1]),
'display:contents makes its children grid items in both shapes');
// The title is still placed by grid, which is what needed the wrapper gone.
const name = /\.mobile-mode \.list-header \.list-header-name \{([^}]*)\}/.exec(boardCss);
assert.ok(name && /grid-column:\s*2/.test(name[1]), 'the title is grid-placed');
});
test('a collapsed list keeps its rotation wrapper (negative)', () => {
// display:contents on .list-rotated would remove the box that does the rotating.
const rule = /\.mobile-mode \.list-header > div:not\(\.list-rotated\)([^{]*)\{/.exec(boardCss);
assert.ok(rule, 'the rule must exist');
assert.ok(/:not\(\.list-move-buttons\)/.test(rule[1]),
'the screen-reader move buttons keep their box too');
});
test('the board reflows instead of overflowing by a scrollbar width', () => {
// 100vw includes the vertical scrollbar. The board canvas scrolls vertically, so
// every child forced to 100vw was a scrollbar wider than the box it sat in - at
// each nesting level - and min-width pinned it there, so it could not reflow.
// Comments blanked first: the note explaining this fix names the unit it replaced.
const code = boardCss.replace(/\/\*[\s\S]*?\*\//g, '');
assert.ok(!/100vw/.test(code),
'mobile board sizing must use 100%, which excludes the scrollbar');
// The elements that were 100vw must still be full width, just measured correctly.
const canvas = /\.mobile-mode \.board-canvas \{([^}]*overflow-x[^}]*)\}/.exec(boardCss);
assert.ok(canvas && /width:\s*100% !important/.test(canvas[1]),
'the canvas is still full width');
});
console.log(`\nmobileModeConsistency: ${passed} tests passed`);