Files
metabase/e2e/support/helpers/e2e-dragndrop-helpers.js
Kamil Mielnik 5a1d677444 RFC 118. Prettier - arrowParens: “always” (#55807)
* Update .prettierrc
- remove "arrowParens": "avoid" so that it defaults to "always" instead

* Run "yarn prettier"
2025-03-27 09:18:07 +00:00

50 lines
1.6 KiB
JavaScript

// Rely on native drag events, rather than on the coordinates
// We have 3 "drag-handles" in this test. Their indexes are 0-based.
export function dragField(startIndex, dropIndex) {
cy.get(".Icon-grabber").should("be.visible").as("dragHandle");
const BUTTON_INDEX = 0;
const SLOPPY_CLICK_THRESHOLD = 10;
// eslint-disable-next-line no-unsafe-element-filtering
cy.get("@dragHandle")
.eq(dropIndex)
.then(($target) => {
const coordsDrop = $target[0].getBoundingClientRect();
// eslint-disable-next-line no-unsafe-element-filtering
cy.get("@dragHandle")
.eq(startIndex)
.then((subject) => {
const coordsDrag = subject[0].getBoundingClientRect();
cy.wrap(subject)
.trigger("mousedown", {
button: BUTTON_INDEX,
clientX: coordsDrag.x,
clientY: coordsDrag.y,
force: true,
})
.trigger("mousemove", {
button: BUTTON_INDEX,
clientX: coordsDrag.x + SLOPPY_CLICK_THRESHOLD,
clientY: coordsDrag.y,
force: true,
});
cy.get("body")
.trigger("mousemove", {
button: BUTTON_INDEX,
clientX: coordsDrop.x,
clientY: coordsDrop.y,
force: true,
})
.trigger("mouseup");
});
});
}
export function dragAndDrop(subjectAlias, targetAlias) {
const dataTransfer = new DataTransfer();
cy.get("@" + subjectAlias).trigger("dragstart", { dataTransfer });
cy.get("@" + targetAlias).trigger("drop", { dataTransfer });
cy.get("@" + subjectAlias).trigger("dragend");
}