mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
578 lines
17 KiB
578 lines
17 KiB
3 years ago
|
// ***********************************************
|
||
|
// This example commands.js shows you how to
|
||
|
// create various custom commands and overwrite
|
||
|
// existing commands.
|
||
|
//
|
||
|
// For more comprehensive examples of custom
|
||
|
// commands please read more here:
|
||
|
// https://on.cypress.io/custom-commands
|
||
|
// ***********************************************
|
||
3 years ago
|
// @author Roman Rezinkin roman.rezinkin@hotmail.com
|
||
3 years ago
|
//
|
||
|
// -- This is a parent command --
|
||
|
// Cypress.Commands.add('login', (email, password) => { ... })
|
||
|
//
|
||
|
//
|
||
|
// -- This is a child command --
|
||
|
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
||
|
//
|
||
|
//
|
||
|
// -- This is a dual command --
|
||
|
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
||
|
//
|
||
|
//
|
||
|
// -- This will overwrite an existing command --
|
||
|
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||
3 years ago
|
|
||
3 years ago
|
import "cypress-file-upload";
|
||
3 years ago
|
import { isXcdb, isPostgres } from "./page_objects/projectConstants";
|
||
3 years ago
|
|
||
3 years ago
|
require("@4tw/cypress-drag-drop");
|
||
3 years ago
|
|
||
3 years ago
|
// for waiting until page load
|
||
3 years ago
|
Cypress.Commands.add("waitForSpinners", () => {
|
||
3 years ago
|
cy.visit("http://localhost:3000", {
|
||
|
retryOnNetworkFailure: true,
|
||
|
timeout: 1200000,
|
||
|
headers: {
|
||
|
"Accept-Encoding": "gzip, deflate",
|
||
|
},
|
||
|
});
|
||
|
cy.get("#nuxt-loading", { timeout: 10_0000 }).should("have.length", 0);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("signinOrSignup", (_args) => {
|
||
3 years ago
|
const args = Object.assign(
|
||
|
{ username: "user@nocodb.com", password: "Password123." },
|
||
|
_args
|
||
|
);
|
||
|
|
||
3 years ago
|
cy.wait(1000);
|
||
|
|
||
3 years ago
|
// signin/signup
|
||
|
cy.get("body").then(($body) => {
|
||
|
// cy.wait(1000)
|
||
|
cy.url().then((url) => {
|
||
|
if (!url.includes("/projects")) {
|
||
|
// handle initial load
|
||
|
if ($body.find(".welcome-page").length > 0) {
|
||
|
cy.wait(8000);
|
||
|
cy.get("body").trigger("mousemove");
|
||
3 years ago
|
cy.snip("LetsBegin");
|
||
3 years ago
|
cy.contains("Let's Begin").click();
|
||
|
cy.get('input[type="text"]', { timeout: 12000 }).type(
|
||
|
args.username
|
||
|
);
|
||
|
cy.get('input[type="password"]').type(args.password);
|
||
3 years ago
|
cy.snip("SignUp");
|
||
3 years ago
|
cy.get('button:contains("SIGN UP")').click();
|
||
|
|
||
|
// handle signin
|
||
|
} else {
|
||
|
cy.get('input[type="text"]', { timeout: 12000 }).type(
|
||
|
args.username
|
||
|
);
|
||
|
cy.get('input[type="password"]').type(args.password);
|
||
3 years ago
|
cy.snip("SignIn");
|
||
3 years ago
|
cy.get('button:contains("SIGN IN")').click();
|
||
|
}
|
||
3 years ago
|
} else if (url.includes("/signin")) {
|
||
|
cy.get('input[type="text"]', { timeout: 12000 }).type(
|
||
|
args.username
|
||
|
);
|
||
|
cy.get('input[type="password"]').type(args.password);
|
||
|
cy.snip("SignIn");
|
||
|
cy.get('button:contains("SIGN IN")').click();
|
||
3 years ago
|
}
|
||
|
});
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// indicates page-load complete
|
||
|
cy.get(".nc-noco-brand-icon", { timeout: 12000 }).should("exist");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// for opening/creating a rest project
|
||
3 years ago
|
Cypress.Commands.add("openOrCreateRestProject", (_args) => {
|
||
3 years ago
|
const args = Object.assign({ new: false }, _args);
|
||
|
|
||
|
// signin/signup
|
||
|
cy.signinOrSignup();
|
||
|
cy.get(".nc-new-project-menu").should("exist");
|
||
3 years ago
|
cy.snip("ProjectPage");
|
||
3 years ago
|
cy.get("body").then(($body) => {
|
||
|
const filter = args.meta
|
||
|
? ".nc-meta-project-row"
|
||
|
: ":not(.nc-meta-project-row)";
|
||
|
// if project exist open
|
||
|
if (
|
||
|
$body.find(".nc-rest-project-row").filter(filter).length &&
|
||
|
!args.new
|
||
|
) {
|
||
|
cy.get(".nc-rest-project-row").filter(filter).first().click();
|
||
|
} else {
|
||
|
cy.contains("New Project")
|
||
|
.trigger("onmouseover")
|
||
|
.trigger("mouseenter");
|
||
|
if (args.meta) {
|
||
|
cy.get(".nc-create-xc-db-project").click();
|
||
|
cy.url({ timeout: 6000 }).should("contain", "#/project/xcdb");
|
||
|
cy.get(".nc-metadb-project-name").type(
|
||
|
"test_proj" + Date.now()
|
||
|
);
|
||
|
cy.contains("button", "Create", { timeout: 3000 }).click();
|
||
|
} else {
|
||
|
cy.get(".nc-create-external-db-project").click();
|
||
|
cy.url({ timeout: 6000 }).should("contain", "#/project");
|
||
|
cy.get(".database-field input").click().clear().type("sakila");
|
||
|
cy.contains("Test Database Connection").click();
|
||
|
cy.contains("Ok & Save Project", { timeout: 3000 }).click();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
cy.url({ timeout: 20000 }).should("contain", "#/nc/");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("refreshTableTab", () => {
|
||
3 years ago
|
cy.task("log", `[refreshTableTab]`);
|
||
3 years ago
|
|
||
3 years ago
|
cy.get(".nc-project-tree")
|
||
|
.find(".v-list-item__title:contains(Tables)", { timeout: 10000 })
|
||
|
.should("exist")
|
||
|
.first()
|
||
|
.rightclick({ force: true });
|
||
3 years ago
|
|
||
3 years ago
|
cy.getActiveMenu()
|
||
|
.find('[role="menuitem"]')
|
||
|
.contains("Tables Refresh")
|
||
|
.should("exist")
|
||
|
.click({ force: true });
|
||
3 years ago
|
|
||
3 years ago
|
cy.toastWait("Tables refreshed");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// tn: table name
|
||
|
// rc: row count. validate row count if rc!=0
|
||
3 years ago
|
Cypress.Commands.add("openTableTab", (tn, rc) => {
|
||
3 years ago
|
cy.task("log", `[openTableTab] ${tn} ${rc}`);
|
||
|
|
||
|
cy.get(".nc-project-tree")
|
||
|
.find(".v-list-item__title:contains(Tables)", { timeout: 10000 })
|
||
|
.should("exist")
|
||
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.contains(tn)
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
3 years ago
|
cy.get(`.project-tab`).contains(tn).should("exist");
|
||
3 years ago
|
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
|
// wait for page rendering to complete
|
||
|
if (rc != 0) {
|
||
|
cy.get(".nc-grid-row").should("have.length", rc);
|
||
|
}
|
||
3 years ago
|
|
||
2 years ago
|
// kludge: add delay to skip flicker
|
||
|
cy.wait(3000)
|
||
3 years ago
|
cy.snip(`GridView_${tn}`);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("closeTableTab", (tn) => {
|
||
3 years ago
|
cy.task("log", `[closeTableTab] ${tn}`);
|
||
3 years ago
|
cy.get(`.project-tab`).contains(tn).should("exist");
|
||
3 years ago
|
cy.get(`[href="#table||||${tn}"]`).find("button.mdi-close").click();
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("openOrCreateGqlProject", (_args) => {
|
||
3 years ago
|
const args = Object.assign({ new: false, meta: false }, _args);
|
||
|
|
||
|
cy.signinOrSignup();
|
||
|
|
||
|
cy.get(".nc-new-project-menu").should("exist");
|
||
|
cy.get("body").then(($body) => {
|
||
|
const filter = args.meta
|
||
|
? ".nc-meta-project-row"
|
||
|
: ":not(.nc-meta-project-row)";
|
||
|
// if project exist open
|
||
|
if (
|
||
|
$body.find(".nc-graphql-project-row").filter(filter).length &&
|
||
|
!args.new
|
||
|
) {
|
||
|
cy.get(".nc-graphql-project-row").filter(filter).first().click();
|
||
|
} else {
|
||
|
cy.contains("New Project")
|
||
|
.trigger("onmouseover")
|
||
|
.trigger("mouseenter");
|
||
|
if (args.meta) {
|
||
|
cy.get(".nc-create-xc-db-project").click();
|
||
|
cy.url({ timeout: 6000 }).should("contain", "#/project/xcdb");
|
||
|
cy.contains("GRAPHQL APIs").closest("label").click();
|
||
|
cy.get(".nc-metadb-project-name").type(
|
||
|
"test_proj" + Date.now()
|
||
|
);
|
||
|
cy.contains("button", "Create", { timeout: 3000 }).click();
|
||
|
} else {
|
||
|
cy.get(".nc-create-external-db-project").click();
|
||
|
cy.url({ timeout: 6000 }).should("contain", "#/project");
|
||
|
cy.contains("GRAPHQL APIs").closest("label").click();
|
||
|
cy.get(".database-field input").click().clear().type("sakila");
|
||
|
cy.contains("Test Database Connection").click();
|
||
3 years ago
|
cy.contains("Ok & Save Project").should('exist').click();
|
||
3 years ago
|
}
|
||
|
}
|
||
|
});
|
||
|
cy.url({ timeout: 20000 }).should("contain", "#/nc/");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
let LOCAL_STORAGE_MEMORY = {};
|
||
|
|
||
|
Cypress.Commands.add("saveLocalStorage", () => {
|
||
3 years ago
|
Object.keys(localStorage).forEach((key) => {
|
||
|
LOCAL_STORAGE_MEMORY[key] = localStorage[key];
|
||
|
});
|
||
3 years ago
|
});
|
||
|
|
||
|
Cypress.Commands.add("restoreLocalStorage", () => {
|
||
3 years ago
|
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
|
||
|
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
|
||
|
});
|
||
3 years ago
|
});
|
||
|
|
||
|
Cypress.Commands.add("getActiveModal", () => {
|
||
3 years ago
|
return cy.get(".v-dialog.v-dialog--active").last();
|
||
3 years ago
|
});
|
||
|
|
||
|
Cypress.Commands.add("getActiveMenu", () => {
|
||
3 years ago
|
return cy.get(".menuable__content__active").last();
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
Cypress.Commands.add("getActiveContentModal", () => {
|
||
3 years ago
|
return cy.get(".v-dialog__content--active").last();
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
Cypress.Commands.add("createTable", (name) => {
|
||
3 years ago
|
cy.get(".add-btn").click();
|
||
3 years ago
|
cy.getActiveMenu().contains("Add new table").should('exist').click()
|
||
3 years ago
|
cy.get('.nc-create-table-card .nc-table-name input[type="text"]')
|
||
|
.first()
|
||
|
.click()
|
||
|
.clear()
|
||
|
.type(name);
|
||
|
|
||
|
// cy.log(isXcdb());
|
||
|
// if (!isXcdb()) {
|
||
|
// cy.get('.nc-create-table-card .nc-table-name-alias input[type="text"]')
|
||
|
// .first()
|
||
|
// .should("have.value", name.toLowerCase());
|
||
|
// }
|
||
|
|
||
3 years ago
|
cy.snip("CreateTable");
|
||
|
cy.snipActiveModal("Modal_CreateTable");
|
||
|
|
||
3 years ago
|
cy.get(".nc-create-table-card .nc-create-table-submit").first().click();
|
||
|
cy.toastWait(`Create table successful`);
|
||
|
cy.get(`.project-tab:contains(${name})`).should("exist");
|
||
|
cy.url().should("contain", `name=${name}`);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("deleteTable", (name, dbType) => {
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click();
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.contains(name)
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click({ force: true });
|
||
|
cy.get(`.project-tab:contains(${name}):visible`).should("exist");
|
||
|
cy.get(".nc-table-delete-btn:visible").click();
|
||
3 years ago
|
cy.snipActiveModal("Modal_DeleteTable");
|
||
3 years ago
|
cy.get("button:contains(Submit)").click();
|
||
|
|
||
|
// only for postgre project
|
||
|
if (dbType === "postgres") cy.toastWait(`Delete trigger successful`);
|
||
|
|
||
|
cy.toastWait(`Delete table successful`);
|
||
3 years ago
|
});
|
||
|
|
||
|
Cypress.Commands.add("renameTable", (oldName, newName) => {
|
||
3 years ago
|
// expand project tree
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click();
|
||
|
|
||
|
// right click on project table name
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.contains(oldName)
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.rightclick();
|
||
|
|
||
|
// choose rename option from menu
|
||
|
cy.getActiveMenu()
|
||
|
.find('[role="menuitem"]')
|
||
|
.contains("Table Rename")
|
||
|
.click({ force: true });
|
||
|
|
||
|
// feed new name
|
||
|
cy.getActiveContentModal().find("input").clear().type(newName);
|
||
|
|
||
3 years ago
|
cy.snipActiveModal("Modal_RenameTable");
|
||
3 years ago
|
// submit
|
||
|
cy.getActiveContentModal().find("button").contains("Submit").click();
|
||
|
|
||
|
cy.toastWait("Table renamed successfully");
|
||
|
|
||
|
// close expanded project tree
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click();
|
||
3 years ago
|
|
||
|
cy.wait(8000)
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("createColumn", (table, columnName) => {
|
||
3 years ago
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click();
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.contains(table)
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click({ force: true });
|
||
|
cy.get(`.project-tab:contains(${table}):visible`).should("exist");
|
||
|
cy.get(".v-window-item--active .nc-grid tr > th:last button").click({
|
||
|
force: true,
|
||
|
});
|
||
|
cy.get(".nc-column-name-input input").clear().type(columnName);
|
||
3 years ago
|
cy.getActiveMenu("Menu_CreateColumn");
|
||
3 years ago
|
cy.get(".nc-col-create-or-edit-card").contains("Save").click();
|
||
|
cy.get("th:contains(new_column)").should("exist");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
Cypress.Commands.add("toastWait", (msg) => {
|
||
3 years ago
|
// cy.get(".toasted:visible", { timout: 12000 }).contains(msg).should("exist");
|
||
|
// cy.get(".toasted:visible", { timout: 12000 })
|
||
|
// .contains(msg)
|
||
|
// .should("not.exist");
|
||
|
cy.wait(3000);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// vn: view name
|
||
|
// rc: expected row count. validate row count if rc!=0
|
||
|
Cypress.Commands.add("openViewsTab", (vn, rc) => {
|
||
3 years ago
|
cy.task("log", `[openViewsTab] ${vn} ${rc}`);
|
||
|
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
3 years ago
|
.should("exist")
|
||
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
|
cy.get(".nc-project-tree")
|
||
|
.contains(vn, { timeout: 6000 })
|
||
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
3 years ago
|
cy.get(`.project-tab`).contains(vn).should("exist");
|
||
3 years ago
|
|
||
|
cy.get(".nc-project-tree")
|
||
3 years ago
|
.find(".v-list-item__title:contains(Tables)")
|
||
|
.should('exist')
|
||
3 years ago
|
.first()
|
||
|
.click({ force: true });
|
||
|
|
||
|
// wait for page rendering to complete
|
||
|
if (rc != 0) {
|
||
|
cy.get(".nc-grid-row").should("have.length", rc);
|
||
|
}
|
||
3 years ago
|
});
|
||
|
|
||
|
Cypress.Commands.add("closeViewsTab", (vn) => {
|
||
3 years ago
|
cy.task("log", `[closeViewsTab] ${vn}`);
|
||
3 years ago
|
cy.get(`.project-tab`).contains(vn).should("exist");
|
||
3 years ago
|
cy.get(`[href="#view||||${vn}"]`)
|
||
3 years ago
|
.find("button.mdi-close")
|
||
|
.click({ force: true });
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
// Support for screen-shots
|
||
|
//
|
||
|
|
||
|
let screenShotDb = [];
|
||
|
|
||
|
// snip entire screen
|
||
|
Cypress.Commands.add("snip", (filename) => {
|
||
|
if (
|
||
|
true === Cypress.env("screenshot") &&
|
||
|
false === screenShotDb.includes(filename)
|
||
|
) {
|
||
|
let storeName = `${screenShotDb.length}_${filename}`;
|
||
|
screenShotDb.push(filename);
|
||
|
cy.wait(1000);
|
||
|
cy.screenshot(storeName, { overwrite: true });
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// snip current modal
|
||
|
Cypress.Commands.add("snipActiveModal", (filename) => {
|
||
|
if (
|
||
|
true === Cypress.env("screenshot") &&
|
||
|
false === screenShotDb.includes(filename)
|
||
|
) {
|
||
|
let storeName = `${screenShotDb.length}_${filename}`;
|
||
|
screenShotDb.push(filename);
|
||
|
cy.wait(1000);
|
||
|
// cy.getActiveModal().screenshot(filename, {
|
||
|
// padding: 0,
|
||
|
// overwrite: true,
|
||
|
// });
|
||
|
cy.screenshot(storeName, { overwrite: true });
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// snip current menu
|
||
|
Cypress.Commands.add("snipActiveMenu", (filename) => {
|
||
|
if (
|
||
|
true === Cypress.env("screenshot") &&
|
||
|
false === screenShotDb.includes(filename)
|
||
|
) {
|
||
|
let storeName = `${screenShotDb.length}_${filename}`;
|
||
|
screenShotDb.push(filename);
|
||
|
cy.wait(1000);
|
||
|
// cy.getActiveMenu().screenshot(filename, {
|
||
|
// padding: 0,
|
||
|
// overwrite: true,
|
||
|
// });
|
||
|
cy.screenshot(storeName, { overwrite: true });
|
||
|
}
|
||
|
});
|
||
|
|
||
3 years ago
|
|
||
3 years ago
|
// Drag n Drop
|
||
|
// refer: https://stackoverflow.com/a/55409853
|
||
3 years ago
|
/*
|
||
3 years ago
|
|
||
|
const getCoords = ($el) => {
|
||
|
const domRect = $el[0].getBoundingClientRect()
|
||
|
const coords = { x: domRect.left + (domRect.width / 2 || 0), y: domRect.top + (domRect.height / 2 || 0) }
|
||
|
|
||
|
return coords
|
||
|
}
|
||
|
|
||
|
const dragTo = (subject, to, opts) => {
|
||
|
|
||
|
opts = Cypress._.defaults(opts, {
|
||
|
// delay inbetween steps
|
||
|
delay: 0,
|
||
|
// interpolation between coords
|
||
|
steps: 0,
|
||
|
// >=10 steps
|
||
|
smooth: false,
|
||
|
})
|
||
|
|
||
|
if (opts.smooth) {
|
||
|
opts.steps = Math.max(opts.steps, 10)
|
||
|
}
|
||
|
|
||
|
const win = subject[0].ownerDocument.defaultView
|
||
|
|
||
|
const elFromCoords = (coords) => win.document.elementFromPoint(coords.x, coords.y)
|
||
|
const winMouseEvent = win.MouseEvent
|
||
|
|
||
|
const send = (type, coords, el) => {
|
||
|
|
||
|
el = el || elFromCoords(coords)
|
||
|
|
||
|
el.dispatchEvent(
|
||
|
new winMouseEvent(type, Object.assign({}, { clientX: coords.x, clientY: coords.y }, { bubbles: true, cancelable: true }))
|
||
|
)
|
||
|
}
|
||
|
|
||
|
const toSel = to
|
||
|
|
||
|
function drag (from, to, steps = 1) {
|
||
|
|
||
|
const fromEl = elFromCoords(from)
|
||
|
|
||
|
const _log = Cypress.log({
|
||
|
$el: fromEl,
|
||
|
name: 'drag to',
|
||
|
message: toSel,
|
||
|
})
|
||
|
|
||
|
_log.snapshot('before', { next: 'after', at: 0 })
|
||
|
|
||
|
_log.set({ coords: to })
|
||
|
|
||
|
send('mouseover', from, fromEl)
|
||
|
send('mousedown', from, fromEl)
|
||
|
|
||
|
cy.then(() => {
|
||
|
return Cypress.Promise.try(() => {
|
||
|
|
||
|
if (steps > 0) {
|
||
|
|
||
|
const dx = (to.x - from.x) / steps
|
||
|
const dy = (to.y - from.y) / steps
|
||
|
|
||
|
return Cypress.Promise.map(Array(steps).fill(), (v, i) => {
|
||
|
i = steps - 1 - i
|
||
|
|
||
|
let _to = {
|
||
|
x: from.x + dx * (i),
|
||
|
y: from.y + dy * (i),
|
||
|
}
|
||
|
|
||
|
send('mousemove', _to, fromEl)
|
||
|
|
||
|
return Cypress.Promise.delay(opts.delay)
|
||
|
|
||
|
}, { concurrency: 1 })
|
||
|
}
|
||
|
})
|
||
|
.then(() => {
|
||
|
|
||
|
send('mousemove', to, fromEl)
|
||
|
send('mouseover', to)
|
||
|
send('mousemove', to)
|
||
|
send('mouseup', to)
|
||
|
_log.snapshot('after', { at: 1 }).end()
|
||
|
|
||
|
})
|
||
|
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
const $el = subject
|
||
|
const fromCoords = getCoords($el)
|
||
|
const toCoords = getCoords(cy.$$(to))
|
||
|
|
||
|
drag(fromCoords, toCoords, opts.steps)
|
||
|
}
|
||
|
|
||
|
Cypress.Commands.addAll(
|
||
|
{ prevSubject: 'element' },
|
||
|
{
|
||
|
dragTo,
|
||
|
}
|
||
|
)
|
||
3 years ago
|
*/
|