mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Selecting the text of a checklist item and releasing the mouse outside the card detail pane closed the card. The checklist items template stops mousedown propagation (for item sorting), so the existing cardDetailsIsDragging guard never engaged and the document-level "click outside to close" handler closed the card. - Add a propagation-independent guard (client/lib/cardCloseGuard.js): isTextSelectionInsideCard() keeps the card open when a live, non-collapsed text selection is anchored inside the card pane. A deliberate click on empty board space collapses the selection outside the card first, so it still closes the card. - Wire the guard into the detailsPane EscapeActions close handler in cardDetails.js. - Add 8 unit tests (client/lib/tests/cardCloseGuard.tests.js) and a Playwright regression spec (tests/playwright/specs/34-checklist-text-selection.e2e.js). - Update CHANGELOG upcoming. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
77 lines
3.1 KiB
JavaScript
77 lines
3.1 KiB
JavaScript
/* eslint-env mocha */
|
|
import { expect } from 'chai';
|
|
import { isTextSelectionInsideCard } from '/client/lib/cardCloseGuard';
|
|
|
|
/**
|
|
* Unit tests for the card-details close guard.
|
|
*
|
|
* Regression #5686 ("Chrome: Selecting text in checklist closes card"):
|
|
* a text-selection drag that starts on the card content and ends with the
|
|
* mouse released outside the card must keep the card open. The guard returns
|
|
* true (keep the card open) only when there is a live, non-collapsed text
|
|
* selection anchored inside the card detail pane.
|
|
*
|
|
* The helper is DOM-light, so a fake `cardDetailsEl` with a `contains()` method
|
|
* and a fake `selection` object are enough to exercise every branch.
|
|
*/
|
|
describe('isTextSelectionInsideCard (#5686)', function() {
|
|
// A node "inside" the card and one "outside" it.
|
|
const insideNode = { id: 'inside' };
|
|
const outsideNode = { id: 'outside' };
|
|
const cardEl = {
|
|
contains(node) {
|
|
return node === insideNode;
|
|
},
|
|
};
|
|
|
|
function selection({ collapsed = false, text = 'selected text', anchor, focus }) {
|
|
return {
|
|
isCollapsed: collapsed,
|
|
toString: () => text,
|
|
anchorNode: anchor,
|
|
focusNode: focus,
|
|
};
|
|
}
|
|
|
|
it('keeps the card open when the selection is anchored inside the card (the #5686 drag)', function() {
|
|
const sel = selection({ anchor: insideNode, focus: outsideNode });
|
|
expect(isTextSelectionInsideCard(sel, cardEl)).to.equal(true);
|
|
});
|
|
|
|
it('keeps the card open when only the focus node is inside the card', function() {
|
|
const sel = selection({ anchor: outsideNode, focus: insideNode });
|
|
expect(isTextSelectionInsideCard(sel, cardEl)).to.equal(true);
|
|
});
|
|
|
|
it('closes the card when the selection is entirely outside the card', function() {
|
|
const sel = selection({ anchor: outsideNode, focus: outsideNode });
|
|
expect(isTextSelectionInsideCard(sel, cardEl)).to.equal(false);
|
|
});
|
|
|
|
it('closes the card for a collapsed (caret-only) selection inside the card', function() {
|
|
const sel = selection({ collapsed: true, anchor: insideNode, focus: insideNode });
|
|
expect(isTextSelectionInsideCard(sel, cardEl)).to.equal(false);
|
|
});
|
|
|
|
it('closes the card when the selected text is empty / whitespace only', function() {
|
|
expect(isTextSelectionInsideCard(selection({ text: '', anchor: insideNode }), cardEl)).to.equal(false);
|
|
expect(isTextSelectionInsideCard(selection({ text: ' ', anchor: insideNode }), cardEl)).to.equal(false);
|
|
});
|
|
|
|
it('matches when the selection node IS the card element itself', function() {
|
|
const sel = selection({ anchor: cardEl, focus: cardEl });
|
|
expect(isTextSelectionInsideCard(sel, cardEl)).to.equal(true);
|
|
});
|
|
|
|
it('is null / undefined safe', function() {
|
|
expect(isTextSelectionInsideCard(null, cardEl)).to.equal(false);
|
|
expect(isTextSelectionInsideCard(selection({ anchor: insideNode }), null)).to.equal(false);
|
|
expect(isTextSelectionInsideCard(undefined, undefined)).to.equal(false);
|
|
});
|
|
|
|
it('always returns a Boolean', function() {
|
|
expect(isTextSelectionInsideCard(selection({ anchor: insideNode }), cardEl)).to.be.a('boolean');
|
|
expect(isTextSelectionInsideCard(null, null)).to.be.a('boolean');
|
|
});
|
|
});
|