Files
wekan/tests/minicardLabelHeight.test.cjs
T
Lauri Ojansivu 40de0df00f Stop element size and spacing changing when the browser window is resized.
Reported on /sign-in and /sign-up: making the window taller made every element
taller and every gap wider; making it shorter shrank them. That is what vh does -
`padding: 3vh 3vw`, `margin-top: 6vh`, `min-height: 4.5vh` - the box is a
percentage of the WINDOW, so the page reflows continuously as you drag the edge
and the same layout looks different on every screen.

It was not only those two pages. 355 such values across 24 stylesheets, on
padding, margin, gap, height, line-height, font-size, border-radius and
box-shadow. They are now the pixel sizes they rendered at on the window they were
tuned for (1vh -> 9px, 1vw -> 14px), so each page looks as it did at that size and
stays that size everywhere else.

Two of them were documented bugs already: minicard.css carries two comments
explaining that the global `.viewer { min-height: 2.5vh }` "reserves a big empty
band under a one-line title, so half of every minicard was white space" on tall
screens. That floor is 22px now, and the modal body's 20vh is 180px.

Viewport units are still right for three things and are kept: a full-viewport box
(100vh/100vw), a CAP that stops content overflowing a small screen (min(), max(),
clamp()), and max-/min-width limits. 274 such uses remain, all deliberate.

The conversion was a token substitution - it cannot move or delete a rule - and
brace balance was asserted unchanged for every file before writing it.

Tests: tests/noViewportSpacing.test.cjs scans every stylesheet under client/ and
fails on any size or spacing measured in vh/vw, while still permitting the three
legitimate shapes (it checks both directions). It blanks block comments first, so
the two minicard.css comments ABOUT this bug are not reported as uses of it. One
existing test pinned the literal `2.5vh` global floor; it now pins a px floor, and
the dependency it documents - that the minicard override compensates for a global
floor - is unchanged.

Thanks to xet7 !
2026-07-25 21:02:54 +03:00

87 lines
3.4 KiB
JavaScript

/**
* Test: minicard label compact height (#6424).
*
* Lightweight, dependency-free CSS regression guard (Node `assert`, runnable via
* `node tests/minicardLabelHeight.test.cjs`). Locks in the fix for #6424, where
* text labels on minicards rendered at ~double height because each label name is
* rendered inside a `.viewer`, and the GLOBAL rule `.viewer { min-height: 2.5vh }`
* (intended for the full content editor) forced every minicard label tall.
*
* The fix (client/components/cards/minicard.css) scopes overrides to the minicard
* text labels so they stay on a single compact line:
* - reset the inner `.viewer` (and its `<p>`) min-height to 0 and render inline,
* - keep the `.card-label` itself compact (min-height:0, nowrap).
*
* This test fails if those overrides are removed/renamed, which would let the
* global 2.5vh min-height regress the label height again.
*/
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
// Collapse whitespace so we can match rule bodies regardless of formatting.
const squish = s => s.replace(/\s+/g, ' ');
const minicardCss = squish(read('client/components/cards/minicard.css'));
const layoutsCss = squish(read('client/components/main/layouts.css'));
// --- Positive: the override rules that keep minicard labels compact exist -----
// 1) The inner viewer's min-height is reset to 0 (and rendered inline) for
// minicard labels.
const viewerRule =
/\.minicard \.minicard-labels \.card-label \.viewer\s*\{([^}]*)\}/.exec(minicardCss);
assert.ok(
viewerRule,
'#6424: missing `.minicard .minicard-labels .card-label .viewer` override rule',
);
assert.match(
viewerRule[1],
/min-height:\s*0/,
'#6424: minicard label `.viewer` must reset min-height to 0',
);
assert.match(
viewerRule[1],
/display:\s*inline/,
'#6424: minicard label `.viewer` should render inline so the label stays one line',
);
// 2) The label box itself stays compact / single line.
const labelRule =
/\.minicard \.minicard-labels \.card-label\s*\{([^}]*)\}/.exec(minicardCss);
assert.ok(
labelRule,
'#6424: missing `.minicard .minicard-labels .card-label` compact rule',
);
assert.match(
labelRule[1],
/min-height:\s*0/,
'#6424: minicard `.card-label` must reset min-height to 0',
);
assert.match(
labelRule[1],
/white-space:\s*nowrap/,
'#6424: minicard `.card-label` should keep the label on a single line',
);
// --- Negative / context: the global rule the fix works around still exists ----
// This documents WHY the scoped override is needed; if the global min-height is
// ever removed the override is harmless, but this assertion makes the dependency
// explicit so the two are not accidentally decoupled without thought.
assert.match(
layoutsCss,
// The global floor is PX now, not 2.5vh: as a percentage of window height it
// grew the empty band under one-line text as the window got taller, which is the
// resize behaviour reported on the auth pages and described in minicard.css.
// The dependency this assertion documents is unchanged - there is still a global
// floor that the minicard override compensates for.
/\.viewer\s*\{[^}]*min-height:\s*\d+px/,
'#6424: expected a global `.viewer` min-height (the rule the minicard override compensates for)',
);
console.log('minicardLabelHeight.test.cjs: all assertions passed');