cypress-dragndrop-kit 1.0.2 → 1.0.3
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/dist/index.d.ts +0 -1
- package/dist/index.js +36 -1
- package/dist/types.d.ts +30 -0
- package/package.json +3 -3
- package/dist/commands.d.ts +0 -1
- package/dist/commands.js +0 -38
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,3 +1,38 @@
|
|
1
1
|
"use strict";
|
2
|
+
/// <reference types="cypress" />
|
3
|
+
/// <reference path="./types.d.ts" />
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
require("./
|
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/dist/types.d.ts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
/// <reference types="cypress" />
|
2
|
+
|
3
|
+
import { DraggableOption } from "./utils";
|
4
|
+
|
5
|
+
declare global {
|
6
|
+
namespace Cypress {
|
7
|
+
interface Chainable {
|
8
|
+
/**
|
9
|
+
*
|
10
|
+
* @description Custom child command for dragging and dropping a chained element to a specified element location
|
11
|
+
* @param targetElement locator for the target element
|
12
|
+
* @example cy.get('[data-id="3"]').dragTo('[data-id="47"]');
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
dragTo(targetElement: string, options?: DraggableOption): void;
|
16
|
+
|
17
|
+
/**
|
18
|
+
*
|
19
|
+
* @description Custom command for dragging and dropping from one element location to another
|
20
|
+
* @param sourceElement locator for the source element
|
21
|
+
* @param targetElement locator for the target element
|
22
|
+
* @example cy.dragAndDrop('[data-id="3"]', '[data-id="47"]');
|
23
|
+
*
|
24
|
+
*/
|
25
|
+
dragAndDrop(sourceElement: string, targetElement: string, options?: DraggableOption): void;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
export {}
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "cypress-dragndrop-kit",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Custom command meant for interacting with draggable elements in the UI",
|
5
5
|
"main": "dist/index.js",
|
6
|
-
"types": "dist/
|
6
|
+
"types": "dist/types.d.ts",
|
7
7
|
"files": ["dist"],
|
8
8
|
"scripts": {
|
9
|
-
"build": "rm -rf dist/* && tsc",
|
9
|
+
"build": "rm -rf dist/* && tsc && cp src/types.d.ts dist/",
|
10
10
|
"publish": "npx semantic-release",
|
11
11
|
"test": "npx cypress run",
|
12
12
|
"test:open": "npx cypress open"
|
package/dist/commands.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/commands.js
DELETED
@@ -1,38 +0,0 @@
|
|
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
|
-
});
|