Files
wekan/tests/titleClickToEdit.test.cjs
T
Lauri Ojansivu 68b575637d Tests: three client guards follow the code they pin again.
The behaviour did not change; each guard read source that later commits
moved, and failed on what it could no longer find:

- sidebarBelowHeader: Template.header.onRendered also wires the full
  screen button since f25957dcf3, and the slice now ran into the new
  onDestroyed. The slice ends at onDestroyed, and the fake environment has
  an inert Fullscreen API.
- maximizedCardPosition: since efaf94242e the maximized selector is also in
  a narrow-screen @media rule that only moves `top` below the header bar on
  a phone. The regex found that rule first; it now reads the top-level one.
- titleClickToEdit: since 1b05673200 the opened card moves with Pointer
  Events, and what a header press does is cardHeaderPress() in
  models/lib/windowDrag.js. The guards read the pointerdown handler and call
  that decision, keeping every assertion: the title edits, links stay links,
  the drag handle wins when drag handles are on, the editor is never dragged.

Each still fails when the behaviour it pins is removed (checked by deleting
onTitleEditZone and by making the maximized card absolute).

Thanks to xet7 !
2026-11-06 16:15:34 +02:00

263 lines
15 KiB
JavaScript

'use strict';
// Minicard titles are drag surfaces; other title editing behavior stays covered.
// Run: node tests/titleClickToEdit.test.cjs
//
// Two titles on the board page worked differently from the list titles beside
// them, and neither difference had a reason:
//
// * a CARD's title (#4990) could only be renamed by opening the card, so
// fixing a typo on a board of forty cards was open, edit, close, forty
// times. A list's title has always been edited in place, right on the
// board; a card's now is too, by the same inlinedForm.
// * the BOARD's title had a pencil beside it. Two targets for one job, and
// the smaller of them was the one that did it.
//
// The board's title keeps its EXISTING popup - `boardChangeTitlePopup`, with
// the title and the description in it. What changed is what you click to get
// there, not the form you land in.
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');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('titleClickToEdit:');
// ── the card, on the board (#4990) ─────────────────────────────────────────
const minicardJade = read('client/components/cards/minicard.jade');
const minicardJs = read('client/components/cards/minicard.js');
const minicardCss = read('client/components/cards/minicard.css');
test('the minicard title is plain content, not an inline-editor trigger', () => {
const title = minicardJade.slice(minicardJade.indexOf('.minicard-title\n'),
minicardJade.indexOf('\n unless minicardCollapsed'));
assert.ok(/span\.minicard-title-text\n/.test(title));
assert.ok(!/js-open-inlined-form|js-minicard-title-form/.test(title));
});
test('the sortable uses the whole minicard without handles and only the handle with them', () => {
const listJs = read('client/components/lists/list.js');
// #6745: one setSortableOptions call, so an unchanged handle is not set again.
assert.match(listJs, /handle: Utils\.isTouchScreenOrShowDesktopDragHandles\(\) \? '\.handle' : '\.minicard'/);
});
test('the title permits board dragscroll only while handles are shown', () => {
const opening = minicardJade.slice(0, minicardJade.indexOf(' if canMoveCard'));
assert.match(opening,
/class="\{\{#unless isTouchScreenOrShowDesktopDragHandles\}\}nodragscroll\{\{\/unless\}\}"/);
});
test('the title text is a block, so the whole line is a drag target', () => {
assert.ok(/\.minicard \.minicard-title \.minicard-title-text \{[^}]*display: block/.test(minicardCss),
'a drag after a short title is still a drag from the title area');
});
test('#6639: links remain above no edit overlay and keep their own click', () => {
assert.ok(!/\.minicard-title-edit-zone/.test(minicardCss),
'CSS cannot recreate the fixed overlay that swallowed short links');
const viewerEvents = read('client/components/main/editor.js');
// The handler's own body, not a fixed 1,000 or 1,200 characters: #6753 added
// the copy-button and in-page-link branches at its top, which pushed these
// lines past the fixed windows although the handler did not change for them.
const start = viewerEvents.indexOf("'click a'(event");
const linkHandler = viewerEvents.slice(start, viewerEvents.indexOf('\n});', start));
const opens = linkHandler.indexOf("window.open(href, '_blank', 'noopener')");
assert.ok(opens > 0, 'an external link still opens its destination');
assert.ok(/FlowRouter\.go\(cardPath\)/.test(linkHandler.slice(0, opens)),
'a linked card opens in the current tab, decided before anything opens a tab');
assert.ok(/event\.stopPropagation\(\)/.test(linkHandler.slice(opens)),
'and its click never reaches the editable title container');
});
test('#6641: the sortable still cancels drags from form controls', () => {
const listJs = read('client/components/lists/list.js');
const sortable = listJs.slice(listJs.indexOf('$cards.sortable({'));
assert.match(sortable.slice(0, 1000),
/cancel: ['"]input, textarea, button, select, option['"]/);
});
test('a label on a minicard opens the labels, and only that (negative)', () => {
// It opened the card details as well: the click reached the minicard behind
// the popup, so one click did two things and the one you did not ask for was
// underneath the one you did.
const handler = minicardJs.slice(minicardJs.indexOf("'click .minicard-labels'"));
const body = handler.slice(0, handler.indexOf('\n },'));
assert.ok(/event\.stopPropagation\(\)/.test(body), 'the click stops at the label');
assert.ok(/event\.preventDefault\(\)/.test(body),
'and does not follow the wrapper link to the card either');
assert.ok(/Popup\.open\("cardLabels"\)/.test(body), 'the labels popup still opens');
// A click in the labels AREA that is not on a label is still the card's.
assert.ok(/if \(!\$\(event\.target\)\.closest\('\.js-card-label'\)\.length\) \{\n\s+return;/.test(body),
'only a label is a label');
assert.ok(!/:hover/.test(body),
'asked of the event, not of `:hover` - which on a touch screen answers about '
+ 'whatever was tapped last');
});
// ── the opened card's title: all of it edits (#6839); the row above drags ──
const cardJade = read('client/components/cards/cardDetails.jade');
const cardJs = read('client/components/cards/cardDetails.js');
const cardCss = read('client/components/cards/cardDetails.css');
// #6839 changed this on purpose: the title was split like a minicard's - the
// trailing half dragged the window - and a click on the right of the title,
// or beside a short last line, did not edit. Now all of it edits, and the
// window is moved from the empty space of the header row above it.
test('the opened card\'s whole title edits (#6839)', () => {
// The drag surface is the header ROW, not the heading: a heading is only as
// wide as its own text, so with a short title "the right half of the title"
// was a few pixels and the empty space beside it belonged to nothing.
assert.ok(/\.card-details-header\.js-card-title-drag-handle\(/.test(cardJade),
'the row is the window\'s drag bar');
assert.ok(/\.card-details-title \{[^}]*min-width: 60%/.test(cardCss),
'and the heading fills it, so half the title is half the bar');
assert.ok(/a\.card-details-title-edit-zone\.js-open-inlined-form/.test(cardJade),
'with a keyboard-focusable zone over the leading half that opens the editor');
const zone = cardCss.slice(cardCss.indexOf('.card-details-title-edit-zone {'));
const body = zone.slice(0, zone.indexOf('}'));
assert.ok(/width: 100%/.test(body) && /inset-inline-start: 0/.test(body),
'all of it - a click anywhere on the title, or beside a short last line, edits');
assert.ok(!/width: 50%/.test(body), 'negative: no longer half of it');
assert.ok(/position: absolute/.test(body), 'as an overlay, so the sentence is not cut in two');
});
// Since 1b05673200 the window moves with Pointer Events (a finger too), and the
// decision of what a press on the header row does is the pure cardHeaderPress()
// in models/lib/windowDrag.js. The handler only describes the pressed element.
const { cardHeaderPress } = require('../models/lib/windowDrag');
const titleHandler = () => {
const handler = cardJs.slice(cardJs.indexOf("'pointerdown .js-card-title-drag-handle'"));
assert.ok(handler.length < cardJs.length, 'the title row has a pointerdown handler');
return handler.slice(0, handler.indexOf('\n },'));
};
const press = { onEditable: false, onTitleEditZone: false, onHandle: false, cardHasHandle: false, onControl: false };
test('the drag handler steps aside for the half that edits (negative)', () => {
// Both live on the same heading, so the one that must NOT fire has to say so.
const body = titleHandler();
assert.ok(/onTitleEditZone: !!closest\('\.card-details-title-edit-zone'\)/.test(body),
'the handler tells the decision when the press is inside the zone');
assert.deepEqual(cardHeaderPress({ ...press, onTitleEditZone: true }), { start: false, deferred: false },
'a press inside the zone is not a drag');
assert.ok(/onControl: !!closest\('a, button'\)/.test(body), 'it tells links and buttons apart');
assert.deepEqual(cardHeaderPress({ ...press, onControl: true }), { start: true, deferred: true },
'and a link is still a link - which is what the close, maximise and menu '
+ 'buttons in that row are: a tap does its job, only a drag moves the window');
assert.ok(/if \(closest\('\.js-card-drag-handle'\)\) return;/.test(body),
'and the drag handle keeps its own handler, so one press moves the window once');
assert.ok(/markCardDetailsUserMoved\(\$card\)/.test(cardJs.slice(cardJs.indexOf('function beginCardWindowDrag'))),
'while a real drag still marks the window as user-placed');
});
test('#6641: the opened-card drag bar steps aside for its live title editor', () => {
const body = titleHandler();
assert.match(body, /onEditable: !!closest\('input, textarea, select, option, \.js-card-details-title'\)/);
assert.deepEqual(cardHeaderPress({ ...press, onEditable: true, onControl: true }), { start: false, deferred: false },
'native text selection in the editor is never a window drag');
const begin = cardJs.slice(cardJs.indexOf('function beginCardWindowDrag'));
assert.ok(begin.indexOf('if (!press.start') < begin.indexOf('preventDefault()'),
'the editor guard returns before the window drag suppresses browser selection');
});
test('the handle appears only when drag handles are on', () => {
const header = cardJade.slice(cardJade.indexOf('template(name="cardDetails")'),
cardJade.indexOf('.card-details-path'));
assert.ok(/if canModifyCard\n\s+if isTouchScreenOrShowDesktopDragHandles\n\s+span\.[^\n]*card-drag-handle/
.test(header), 'the handle is behind that question');
// ...and then it is the only drag source: the bar steps aside when the
// card has a handle (#6839).
assert.ok(/closest\('\.card-details'\)\.querySelector\('\.js-card-drag-handle'\)/.test(titleHandler()),
'the handler tells the decision when this card has a handle');
assert.deepEqual(cardHeaderPress({ ...press, cardHasHandle: true, onControl: true }), { start: false, deferred: false },
'with handles on, only the handle moves the window');
assert.ok(/\.card-details:not\(\.card-details-with-handle\) \.card-details-header \{\s*cursor: move;/.test(cardCss),
'and the bar shows it moves the window only while there is no handle');
assert.ok(/card-details-with-handle\{\{\/if\}\}/.test(cardJade)
|| /\{\{#if isTouchScreenOrShowDesktopDragHandles\}\}card-details-with-handle/.test(cardJade),
'and the class is set from the same question the handle asks');
});
// ── the board, in the header bar ───────────────────────────────────────────
const headerJade = read('client/components/main/header.jade');
const headerJs = read('client/components/main/header.js');
const headerCss = read('client/components/main/header.css');
const boardHeaderJade = read('client/components/boards/boardHeader.jade');
test('the board title text opens the rename popup', () => {
assert.ok(/class="\{\{#if canEditBoardTitle\}\}js-edit-board-title is-editable\{\{\/if\}\}"/
.test(headerJade), 'the title itself carries the handle');
assert.ok(/Popup\.open\('boardChangeTitle'\)\.call\(board, evt\)/.test(headerJs),
'and opens the popup that already existed, with the board as its context');
assert.ok(/template\(name="boardChangeTitlePopup"\)/.test(boardHeaderJade),
'which is unchanged - the title and the description, as before');
});
test('there is no separate edit button any more (negative)', () => {
assert.ok(!/\+boardEditTitleButton/.test(headerJade), 'no pencil in the bar');
assert.ok(!/template\(name="boardEditTitleButton"\)/.test(boardHeaderJade),
'and no template left behind for one');
const boardHeaderJs = read('client/components/boards/boardHeader.js');
assert.ok(!/Template\.boardEditTitleButton\.events/.test(boardHeaderJs),
'nor a handler with nothing to handle');
assert.ok(!/'click \.js-edit-board-title': Popup\.open/.test(boardHeaderJs),
'including the one in boardHeaderButtons, whose element went with the bar');
});
test('only a board admin gets it', () => {
const helper = headerJs.slice(headerJs.indexOf('canEditBoardTitle()'));
const body = helper.slice(0, helper.indexOf('\n },'));
assert.ok(/Utils\.getCurrentBoardId\(\)/.test(body), 'on a board page');
assert.ok(/isBoardAdmin\(\)/.test(body), 'and only for an admin of it');
const handler = headerJs.slice(headerJs.indexOf("'click .js-edit-board-title'(evt)"));
assert.ok(/isBoardAdmin\(\)\) return;/.test(handler.slice(0, handler.indexOf('\n },'))),
'checked again where it acts, not only where it draws');
});
test('an empty board title can still be clicked (negative)', () => {
// The trap: a board with no title renders no text, and an element with no
// content is zero pixels wide. Without a minimum there would be nothing to
// aim at, and an empty title could never be given one.
const rule = headerCss.slice(headerCss.indexOf('.header-page-title.is-editable {'));
const body = rule.slice(0, rule.indexOf('}'));
assert.ok(/min-width: 4em/.test(body), 'a strip of the bar stays clickable');
assert.ok(/min-height: 1\.3em/.test(body), 'in the other axis too');
assert.ok(/display: inline-block/.test(body),
'without which neither minimum applies to an inline span');
});
test('the tooltip on the title still carries the whole path', () => {
// The bar shows the root of the path and puts the rest in the tooltip; the
// class was added beside that attribute, not instead of it.
assert.ok(/span\.header-page-title\(title="\{\{headerTitleFullPath\}\}"/.test(headerJade),
'the tooltip survived');
});
test('the stickers popup is wide enough to see them at once', () => {
// A hundred and fifty icons at eight per row is a column taller than the
// screen: choosing one meant scrolling past most of them.
const popupCss = read('client/components/main/popup.css');
assert.ok(/data-popup='cardStickersPopup'\] \{\n\s+width: min\(90vw, 720px\)/.test(popupCss),
'the popup is as wide as the colour pickers');
const offset = read('client/lib/popupOffset.js');
assert.ok(/cardStickersPopup: 720/.test(offset),
'and the clamp knows that width, or it would place it half off screen');
const details = read('client/components/cards/cardDetails.css');
const picker = details.slice(details.indexOf('.card-stickers-picker {'));
const body = picker.slice(0, picker.indexOf('}'));
assert.ok(/grid-template-columns: repeat\(auto-fill, minmax\(40px, 1fr\)\)/.test(body),
'and the picker fills it with as many columns as fit');
assert.ok(!/max-width: 320px/.test(body),
'rather than stopping at eight and leaving the new width empty');
});
console.log(`\ntitleClickToEdit: ${passed} tests passed`);