mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Three things, as asked. NO DUPLICATE BOARD NAME. The second bar drew the board's title in an `h1` of its own, under the same name in the bar above it. The first bar has said it since the first step of this work; the h1 is gone. THE PENCIL IS BESIDE THE NAME. Renaming a board belongs next to the board's name, not in a bar of its own, so `boardEditTitleButton` renders immediately right of the title in the first bar. Board admins only, as before. EVERYTHING ELSE IS AN ICON, LEFT OF THE BELL. Visibility, watch, star, sort, the board's rule buttons, filter, search, dependencies and Multi-Selection, each named by a tooltip and none carrying a visible label. The bar is one row shared with the logo, the starred boards, the view menu, the bell and the user menu; ten labelled buttons do not fit at any width. The desktop/mobile duplication went with it. The old bar wrote the whole set out TWICE - `unless isMiniScreen` and `if isMiniScreen` - because a row of labelled buttons does not fit on a phone. Icons do, so one copy serves both, and the two switches that had to be kept in step are gone rather than kept in step. headerBarControls.jade is deleted. It held one Search button and one Multi-Selection button, written for this bar and All Boards'; both bars are gone now, so a template shared by nobody was indirection rather than sharing. Every route reference goes with the bar: config/router.js names no headerBar at all any more. Six guards followed, and four of them existed only to measure this bar: the title-plus-buttons row that a long board title split across two lines, the wrapper that fixed it, the phone layout, and the hamburger that shared the first row with the title. All of that was one problem, and the problem is gone with the row. Each says so where it used to measure it, rather than being deleted. Thanks to xet7 !
203 lines
9.7 KiB
JavaScript
203 lines
9.7 KiB
JavaScript
'use strict';
|
|
|
|
// The board bar (the second header bar: board title, edit, visibility, watch,
|
|
// star, sort | filter, search, view, dependencies, multi-selection, hamburger)
|
|
// wrapped onto TWO rows on iPad landscape. Measured from the report at a 1180 CSS
|
|
// px viewport: the rows needed ~613px + ~691px = ~1304px on one line, ~124px more
|
|
// than the viewport.
|
|
//
|
|
// Almost all of that is per-button chrome rather than text, so header.css halves
|
|
// the chrome between 801px and 1400px instead of hiding anything, and drops the
|
|
// labels to icons only in the narrower tablet band (801-1000px) where even the
|
|
// halved chrome cannot fit them. This test guards the ARITHMETIC - that the
|
|
// halving still frees more than the measured deficit - not just that some rule is
|
|
// present.
|
|
//
|
|
// Run: node tests/boardHeaderOneLine.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 cssPath = path.join(root, 'client/components/main/header.css');
|
|
const css = fs.readFileSync(cssPath, 'utf8');
|
|
const jade = fs.readFileSync(
|
|
path.join(root, 'client/components/boards/boardHeader.jade'), 'utf8');
|
|
|
|
// The measured one-line shortfall on iPad landscape (1180px viewport).
|
|
const DEFICIT_PX = 124;
|
|
// Buttons on the bar in the reported screenshot: edit, visibility, watch, star,
|
|
// sort | filter, search, view toggle, dependencies, multi-selection, hamburger.
|
|
const BUTTON_COUNT = 11;
|
|
|
|
// Body of the @media block whose query contains `queryPart`, brace-balanced.
|
|
function mediaBlock(queryPart) {
|
|
const at = css.indexOf(`@media ${queryPart}`);
|
|
assert.ok(at >= 0, `@media ${queryPart} must exist in header.css`);
|
|
const open = css.indexOf('{', at);
|
|
let depth = 0;
|
|
for (let i = open; i < css.length; i += 1) {
|
|
if (css[i] === '{') depth += 1;
|
|
else if (css[i] === '}') {
|
|
depth -= 1;
|
|
if (depth === 0) return { body: css.slice(open + 1, i), start: at };
|
|
}
|
|
}
|
|
throw new Error(`unbalanced braces after @media ${queryPart}`);
|
|
}
|
|
|
|
// First declaration `prop` of the rule whose selector is `selector`, as a number
|
|
// of px. `margin: 0 6px` -> 6 (the side margin is what costs horizontal room).
|
|
function sideMarginPx(scope, selector, prop) {
|
|
const rule = new RegExp(
|
|
`${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\{([^}]*)\\}`);
|
|
const m = rule.exec(scope);
|
|
assert.ok(m, `rule "${selector}" must exist`);
|
|
const decl = new RegExp(`${prop}\\s*:([^;]*);`).exec(m[1]);
|
|
assert.ok(decl, `"${selector}" must declare ${prop}`);
|
|
const values = decl[1].trim().split(/\s+/);
|
|
// margin: 0 12px -> the second value; margin-inline-end: 10px -> the only one.
|
|
const px = values.length > 1 ? values[1] : values[0];
|
|
const n = parseFloat(px);
|
|
assert.ok(!Number.isNaN(n), `${prop} of "${selector}" must be a px number`);
|
|
return n;
|
|
}
|
|
|
|
const BASE = css.slice(0, css.indexOf('@media'));
|
|
const tablet = mediaBlock('screen and (min-width: 801px) and (max-width: 1400px)');
|
|
const portrait = mediaBlock('screen and (min-width: 801px) and (max-width: 1000px)');
|
|
|
|
const boardCss = fs.readFileSync(path.join(root, 'client/components/boards/boardHeader.css'), 'utf8');
|
|
|
|
console.log('boardHeaderOneLine:');
|
|
|
|
test('the base per-button chrome is what the fix was measured against', () => {
|
|
// If these change, the saving below changes with them - recompute the deficit.
|
|
assert.strictEqual(
|
|
sideMarginPx(BASE, '#header #header-main-bar .board-header-btn', 'margin'), 12);
|
|
assert.strictEqual(
|
|
sideMarginPx(BASE, '#header #header-main-bar .board-header-btn i.fa', 'margin'), 10);
|
|
assert.strictEqual(
|
|
sideMarginPx(BASE, '#header #header-main-bar .board-header-btn i.fa + span',
|
|
'margin-inline-end'), 10);
|
|
});
|
|
|
|
test('the tablet block halves the chrome, freeing more than the deficit', () => {
|
|
const btn = sideMarginPx(tablet.body, '#header #header-main-bar .board-header-btn', 'margin');
|
|
const icon = sideMarginPx(tablet.body, '#header #header-main-bar .board-header-btn i.fa', 'margin');
|
|
const span = sideMarginPx(tablet.body,
|
|
'#header #header-main-bar .board-header-btn i.fa + span', 'margin-inline-end');
|
|
|
|
// Both sides of the button and both sides of the icon, plus the label gap.
|
|
const perButton = 2 * (12 - btn) + 2 * (10 - icon) + (10 - span);
|
|
const freed = perButton * BUTTON_COUNT;
|
|
assert.ok(freed >= DEFICIT_PX,
|
|
`halving the chrome frees ${freed}px but the bar is ${DEFICIT_PX}px too wide`);
|
|
// Keep real slack for languages with longer labels than the Finnish report.
|
|
assert.ok(freed >= DEFICIT_PX * 2,
|
|
`only ${freed}px freed - too tight for longer translations`);
|
|
});
|
|
|
|
test('the tablet block only shrinks empty space, never the touch target', () => {
|
|
// #6419 sized these buttons for touch. Shrinking them vertically or making the
|
|
// text smaller is how that regression would come back, so the block may only
|
|
// move horizontal space around.
|
|
for (const prop of ['height', 'font-size', 'line-height', 'min-height']) {
|
|
assert.ok(!new RegExp(`(^|[;{\\s])${prop}\\s*:`).test(tablet.body),
|
|
`the tablet block must not set ${prop} - it may only change spacing`);
|
|
}
|
|
// Every rule that targets a BUTTON may declare margins and nothing else (the
|
|
// h1 title's horizontal padding is fine - it is not a touch target).
|
|
// Capture selector and body directly, so neither brace ends up in the text and
|
|
// there is nothing to strip afterwards.
|
|
const RULE = /([^{}]+)\{([^{}]*)\}/g;
|
|
let rule;
|
|
while ((rule = RULE.exec(tablet.body)) !== null) {
|
|
const [, selector, body] = rule;
|
|
if (!/board-header-btn/.test(selector)) continue;
|
|
for (const decl of body.split(';')) {
|
|
if (!decl.trim()) continue;
|
|
const prop = decl.split(':')[0].trim();
|
|
assert.ok(/^margin/.test(prop),
|
|
`"${selector.trim()}" sets ${prop}; buttons may only have margins changed`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('tablet portrait falls back to icons only', () => {
|
|
assert.ok(
|
|
/#header #header-main-bar \.board-header-btn i\.fa \+ span\s*\{[^}]*display:\s*none/
|
|
.test(portrait.body),
|
|
'between 801px and 1000px the labels must be hidden so the bar still fits');
|
|
});
|
|
|
|
test('phones (<= 800px) keep their existing treatment', () => {
|
|
// The tablet rules must start above the phone breakpoint, so the phone block -
|
|
// which hides labels and grows the buttons to 44px - is untouched.
|
|
assert.ok(/min-width:\s*801px/.test(css.slice(tablet.start, tablet.start + 120)),
|
|
'the tablet block must start at 801px, above the phone breakpoint');
|
|
// Anchored on the #6419 comment: the same query text also opens a NESTED media
|
|
// block earlier in the file, so matching the query string alone finds the wrong one.
|
|
const anchor = css.indexOf('/* #6419: taller bar');
|
|
assert.ok(anchor >= 0, 'the phone block must still be there');
|
|
const phoneStart = css.lastIndexOf('@media', anchor);
|
|
assert.ok(/max-width:\s*800px/.test(css.slice(phoneStart, anchor)),
|
|
'the #6419 sizing must still live under the <= 800px phone query');
|
|
const phone = css.slice(phoneStart, css.indexOf('#header-quick-access', anchor));
|
|
assert.ok(/height:\s*44px/.test(phone),
|
|
'the phone block must still give 44px touch targets');
|
|
assert.ok(/i\.fa \+ span\s*\{\s*display:\s*none/.test(phone),
|
|
'the phone block must still hide the labels');
|
|
});
|
|
|
|
test('the tablet rules come after the base rules they override', () => {
|
|
// Same selectors, and a media query adds no specificity - source order decides.
|
|
const baseAt = css.indexOf('#header #header-main-bar .board-header-btn {');
|
|
assert.ok(baseAt >= 0 && baseAt < tablet.start,
|
|
'the tablet overrides must appear after the base .board-header-btn rule');
|
|
assert.ok(css.indexOf('@media print') > tablet.start,
|
|
'the tablet block belongs with the screen rules, before @media print');
|
|
});
|
|
|
|
// ── The second header bar itself is gone ────────────────────────────────────
|
|
//
|
|
// Everything below this point used to measure ONE thing: the board's second
|
|
// header bar was a title and three button groups on a single flex row, and a
|
|
// long board title pushed some buttons to a second row and not others. The
|
|
// wrapper, the phone layout, the hamburger sharing the first row with the title
|
|
// - all of it existed to keep that row together.
|
|
//
|
|
// There is no such row. The board's name is in the FIRST header bar, its rename
|
|
// pencil is beside the name, its controls are icons beside those, and there is
|
|
// one hamburger for the whole app. tests/headerBars.test.cjs pins where each of
|
|
// those sits; what is left to check here is that the bar really is gone, so
|
|
// nothing quietly brings it back. docs/Design/Page/Header.md
|
|
|
|
test('the board has no second header bar to lay out', () => {
|
|
assert.ok(!/template\(name="boardHeaderBar"\)/.test(jade), 'the bar is gone');
|
|
assert.ok(!/h1\.header-board-menu/.test(jade), 'and its copy of the board name');
|
|
assert.ok(!/\.board-header-btns-group/.test(jade), 'and the wrapper of its groups');
|
|
for (const group of ['left', 'center', 'right']) {
|
|
assert.ok(!new RegExp(`\\.board-header-btns\\.${group}`).test(jade), `and .${group}`);
|
|
}
|
|
assert.ok(!/js-toggle-sidebar/.test(jade), 'and its own hamburger');
|
|
const router = fs.readFileSync(path.join(root, 'config/router.js'), 'utf8');
|
|
assert.ok(!/boardHeaderBar/.test(router), 'and no route names it');
|
|
|
|
// Where they went.
|
|
const header = fs.readFileSync(path.join(root, 'client/components/main/header.jade'), 'utf8');
|
|
assert.ok(/span\.header-page-title/.test(header), 'the name is in the first bar');
|
|
assert.ok(/if isBoardPage\n\s+\+boardEditTitleButton/.test(header), 'the pencil beside it');
|
|
assert.ok(/if isBoardPage\n\s+\+boardHeaderButtons/.test(header), 'the controls beside those');
|
|
});
|
|
|
|
console.log(`\nboardHeaderOneLine: ${passed} tests passed`);
|