cypress-dragndrop-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands.d.ts +1 -0
- package/commands.js +38 -0
- package/index.d.ts +2 -0
- package/index.js +3 -0
- package/npm-shrinkwrap.json +8482 -0
- package/package.json +29 -0
- package/utils.d.ts +13 -0
- package/utils.js +10 -0
package/commands.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/commands.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
/// <reference types="cypress" />
|
3
|
+
/// <reference path="./types.d.ts" />
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
+
const utils_1 = require("./utils");
|
6
|
+
Cypress.Commands.add("dragTo", { prevSubject: 'element' }, (sourceElement, targetElement, options) => {
|
7
|
+
cy.get(targetElement).first().then(([target]) => {
|
8
|
+
cy.wrap(sourceElement).first().then(([source]) => {
|
9
|
+
var _a;
|
10
|
+
let sourceCoordinates = source.getBoundingClientRect();
|
11
|
+
let targetCoordinates = target.getBoundingClientRect();
|
12
|
+
const isScrollingDown = targetCoordinates.top - sourceCoordinates.top > 0;
|
13
|
+
const isScrollingRight = targetCoordinates.right - sourceCoordinates.right > 0;
|
14
|
+
if (isScrollingDown || isScrollingRight) {
|
15
|
+
cy.get(targetElement).first().scrollIntoView();
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
const startX = sourceCoordinates.left + sourceCoordinates.width / 2;
|
19
|
+
const startY = sourceCoordinates.top + sourceCoordinates.height / 2;
|
20
|
+
sourceCoordinates = Object.assign(Object.assign({}, sourceCoordinates), { x: startX, y: startY });
|
21
|
+
const endX = targetCoordinates.left + targetCoordinates.width / 2;
|
22
|
+
const endY = targetCoordinates.top + targetCoordinates.height / 2;
|
23
|
+
targetCoordinates = Object.assign(Object.assign({}, targetCoordinates), { x: endX, y: endY });
|
24
|
+
}
|
25
|
+
cy.wrap(source)
|
26
|
+
.trigger("mousedown", (0, utils_1.params)(sourceCoordinates))
|
27
|
+
.wait((_a = options === null || options === void 0 ? void 0 : options.pressDelay) !== null && _a !== void 0 ? _a : 0)
|
28
|
+
.trigger("mousemove", (0, utils_1.params)(sourceCoordinates, 10));
|
29
|
+
cy.get("body")
|
30
|
+
.trigger("mousemove", (0, utils_1.params)(targetCoordinates))
|
31
|
+
.wait(1000)
|
32
|
+
.trigger("mouseup", { force: true });
|
33
|
+
});
|
34
|
+
});
|
35
|
+
});
|
36
|
+
Cypress.Commands.add("dragAndDrop", (sourceElement, targetElement, options) => {
|
37
|
+
cy.get(sourceElement).dragTo(targetElement, options);
|
38
|
+
});
|
package/index.d.ts
ADDED
package/index.js
ADDED