Files
wekan/tests/hiddenNotOutrankedById.test.cjs
T
Lauri Ojansivu 56e1ad0980 Fixes from the running everything tests: a PDF beside two empty boxes, two nameless panes, and seven tests that asked the wrong question.
Fixed in WeKan:
- The attachment slideshow showed #zip-viewer and #rich-viewer, two empty
  white boxes, beside every PDF, image and video: their id rule's
  display:flex outranked .hidden. A PDF got a third of a 1600px window,
  468px. tests/hiddenNotOutrankedById.test.cjs looks for the same mistake
  in every template and stylesheet.
- Admin Panel / Problems / API: a person link with a user id and no text
  had no name (axe link-name). personLinkLabel falls back to the
  account's name, then its id.
- Admin Panel / Attachments / Encrypt, hidden from the menu while
  ATTACHMENTS_PASSPHRASE is unset but still at its address, had no pane
  title. paneTitle() takes the page's own title for a pane with no menu
  entry.

The tests corrected, each to what the app now rightly does:
- attachment-content-search: one "added" history row per upload, the
  hash on the attachment (5ba1098521 removed the duplicate row).
- card-details-width: the resize handle is pressed once the window has
  settled; while it opens, its corner is below the window's edge.
- card-title-edit-and-move-6839 and card-window-touch-drag: a popup is
  moved toward the side with room, as far as there is; the card menu is
  1200px wide in a 1280px window and a drag keeps it 12px inside.
- editor-enter-preference and keep-add-card-form-open-6827: Escape goes
  back from Change Settings to the member menu first; closed until no
  popup is left.
- list-sync-time-estimates: the next sync waits for the previous one to
  release its lease, which comes after the card is written.

Thanks to xet7 !
2026-11-25 01:30:17 +02:00

59 lines
2.8 KiB
JavaScript

'use strict';
// #6612 again: `.hidden { display: none }` is a class rule, and an id rule
// that sets `display` outranks it. The attachment slideshow's #zip-viewer and
// #rich-viewer got `display: flex`, so while "hidden" they still showed as two
// empty white boxes beside every PDF, image and video, each taking a third of
// the width - the PDF was 468 px wide in a 1600 px window.
//
// So, everywhere in client/: an element a template marks `#id.hidden` whose id
// rule sets display must also have a `#id.hidden` rule that hides it again.
// Negative: the rule is found missing in a sample that lacks it.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..');
function walk(dir, out = []) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) walk(p, out); else out.push(p);
}
return out;
}
const files = walk(path.join(ROOT, 'client'));
const read = f => fs.readFileSync(f, 'utf8');
// Ids a template starts hidden: `#zip-viewer.hidden` or `img#image-viewer.hidden`.
function hiddenIds(jade) {
return new Set([...jade.matchAll(/(?:^|\s|[a-z])#([A-Za-z][\w-]*)\.hidden\b/gm)].map(m => m[1]));
}
// Ids whose own rule (the id alone, or in a selector list) sets display other than none.
function offenders(css, ids) {
const text = css.replace(/\/\*[\s\S]*?\*\//g, '');
const bad = [];
for (const id of ids) {
const own = [...text.matchAll(/([^{}]+)\{([^}]*)\}/g)]
.filter(([, sel]) => sel.split(',').some(s => s.trim() === `#${id}`));
const shows = own.some(([, , body]) => /(^|;)\s*display\s*:(?!\s*none)/.test(body));
const hides = [...text.matchAll(/([^{}]+)\{([^}]*)\}/g)]
.some(([, sel, body]) => sel.split(',').some(s => s.trim() === `#${id}.hidden`) && /display\s*:\s*none/.test(body));
if (shows && !hides) bad.push(`#${id}`);
}
return bad;
}
test('no element a template starts hidden is shown by its own id rule', () => {
const ids = new Set();
for (const f of files.filter(f => f.endsWith('.jade'))) for (const id of hiddenIds(read(f))) ids.add(id);
assert.ok(ids.has('zip-viewer') && ids.has('rich-viewer') && ids.has('pdf-viewer'), 'the slideshow viewers are found');
const css = files.filter(f => f.endsWith('.css')).map(read).join('\n');
assert.deepEqual(offenders(css, ids), []);
});
test('negative: an id rule that sets display without its .hidden rule is caught', () => {
assert.deepEqual(offenders('#a, #b {\n display: flex;\n}\n#b.hidden { display: none; }', new Set(['a', 'b'])), ['#a']);
assert.deepEqual(offenders('#a { display: none; }', new Set(['a'])), []);
assert.deepEqual([...hiddenIds(' object#pdf-viewer.hidden(type="x")\n #zip-viewer.hidden')].sort(), ['pdf-viewer', 'zip-viewer']);
});