Files
wekan/tests/dragscrollReattach.test.cjs
T
Lauri Ojansivu c185f5e982 Moving a card no longer pans the board at the same time.
On a board large enough to have scrollbars in both directions, dragging a
card sometimes moved the card, sometimes scrolled the list, sometimes
scrolled the board, and often several of those at once, so the card could
not be dropped where it was aimed.

A board runs three drag-scroll implementations over the same pointer: the
dragscroll library, bound separately to `.board-canvas`, to every swimlane
and to every lane; the `mousedown .board-canvas` lane pan in swimlanes.js;
and jQuery UI sortable, which is the one that is supposed to move the card.
Nothing stood any of them down while a drag was in progress. swimlanes.js
did try, for list drags, but called `dragscroll.reset()` FIRST and removed
the class afterwards - reset() binds to whatever carries the class at that
moment, so the listeners stayed - and it left the canvas tagged anyway. The
lane pan ignored the `nodragscroll` marker the library honours, so pressing
a minicard, which carries that marker exactly because it is the card's drag
handle, started a horizontal pan that ran alongside the card drag.

Now client/lib/boardDragscroll.js suspends drag-scrolling for the whole
drag - class off, THEN reset - and restores exactly the elements it took it
from, so a board route does not gain panning it deliberately turned off.
Every sortable on the board (cards, lists, swimlanes) suspends in start and
resumes in stop, a window mouseup/touchend/dragend restores in case a drag
never reaches its stop handler, and a swimlane re-rendered mid-drag does not
re-arm panning under the pointer. The lane pan now refuses to start on
`.nodragscroll` or on a drag handle, and gives way if a drag begins after
the press. The drag handles themselves are marked `nodragscroll`: a press on
a handle moves the item, it never pans the board.

tests/boardDragScrollDuringDrag.test.cjs pins the order of the two steps,
the restore-what-was-suspended rule, the safety net, the suspend/resume in
every sortable and the two markers; specs/37-card-drag-sort.e2e.js drags a
card sideways on a 12-list board and pins that neither the lane nor the
canvas scrolls while it moves, and that panning is back afterwards.

Thanks to mueschel and xet7 !

Fixes #6558,
2026-07-28 22:25:15 +03:00

78 lines
3.6 KiB
JavaScript

'use strict';
// Regression guard: "only the top swimlane is usable / dragscroll is not enabled"
// after the board's swimlanes/lists render or change.
//
// @wekanteam/dragscroll attaches its MOUSE handlers PER element inside reset(),
// so reset() must be re-called after the set of `.dragscroll` containers changes.
// boardBody.js calls it in onRendered (once) and in one autorun. That autorun used
// to depend only on the touch/permission reads, so when swimlanes/lists rendered
// AFTER onRendered — adaptive lazy card loading (#6480), the on-open data-repair
// adding a default swimlane (#6484), or a board switch that reuses this template
// instance without re-firing onRendered — the new containers never got mouse
// handlers and drag-scrolling was dead (touch still worked via the document-
// delegated dragscrollTouch). The fix makes the autorun read the board view +
// swimlanes + lists so reset() re-runs when the rendered containers change.
//
// The re-scan itself goes through resetBoardDragscroll() (client/lib/boardDragscroll.js)
// since #6558, which is dragscroll.reset() plus "stay suspended while a card is being
// dragged"; either spelling satisfies this file, what it pins is the reactive reads.
//
// DOM/Blaze-coupled runtime code, so it is guarded at the source level.
// Run: node tests/dragscrollReattach.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const js = fs.readFileSync(
path.join(repoRoot, 'client/components/boards/boardBody.js'),
'utf8',
);
// Isolate the autorun that re-scans the dragscroll containers (the one set up in
// onRendered), so the assertions cannot be satisfied by unrelated code elsewhere in
// the file.
const RESET = /(?:dragscroll\.reset|resetBoardDragscroll)\(\);/g;
const resets = [...js.matchAll(RESET)];
assert.ok(resets.length > 0, 'expected a dragscroll re-scan call in boardBody.js');
const inAutorun = resets.find(m => js.lastIndexOf('this.autorun(', m.index) !== -1
&& js.slice(js.lastIndexOf('this.autorun(', m.index), m.index).includes('.swimlanes()'));
const resetIdx = (inAutorun || resets[0]).index;
const resetLen = (inAutorun || resets[0])[0].length;
const autorunStart = js.lastIndexOf('this.autorun(', resetIdx);
assert.ok(autorunStart !== -1, 'the re-scan must live inside a this.autorun()');
// The autorun body up to and including the re-scan call.
const body = js.slice(autorunStart, resetIdx + resetLen);
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
test('the dragscroll autorun establishes a dependency on the current board', () => {
assert.ok(/Utils\.getCurrentBoard\(\)/.test(body),
'the autorun must read Utils.getCurrentBoard() so it re-runs on board switch');
});
test('it reads the swimlanes and lists so reset() re-runs when they change', () => {
assert.ok(/\.swimlanes\(\)/.test(body),
'the autorun must read board.swimlanes() as a reactive dependency');
assert.ok(/\.draggableLists\(\)|\.lists\(\)/.test(body),
'the autorun must read the board lists as a reactive dependency');
assert.ok(/Utils\.boardView\(\)/.test(body),
'the autorun must read Utils.boardView() so a view switch re-attaches dragscroll');
});
test('the reactive reads come BEFORE dragscroll.reset()', () => {
const swimIdx = body.indexOf('.swimlanes()');
const resetInBody = body.search(/(?:dragscroll\.reset|resetBoardDragscroll)\(\)/);
assert.ok(swimIdx !== -1 && swimIdx < resetInBody,
'the swimlanes/lists reads must precede the re-scan in the autorun');
});
console.log(`\nAll ${passed} dragscroll re-attach tests passed`);