2022-11-08 04:21:10 -08:00
|
|
|
// ***********************************************
|
|
|
|
// 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
|
|
|
|
// ***********************************************
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- 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) => { ... })
|
2023-02-08 12:41:35 -08:00
|
|
|
import 'cypress-real-events';
|
2023-03-09 08:08:47 -08:00
|
|
|
import { WorkflowsPage, SigninPage, SignupPage, SettingsUsersPage, WorkflowPage } from '../pages';
|
2022-12-15 07:39:59 -08:00
|
|
|
import { N8N_AUTH_COOKIE } from '../constants';
|
2022-11-24 03:52:09 -08:00
|
|
|
import { MessageBox } from '../pages/modals/message-box';
|
2022-11-08 04:21:10 -08:00
|
|
|
|
|
|
|
Cypress.Commands.add('getByTestId', (selector, ...args) => {
|
2022-12-15 07:39:59 -08:00
|
|
|
return cy.get(`[data-test-id="${selector}"]`, ...args);
|
|
|
|
});
|
2022-11-08 04:21:10 -08:00
|
|
|
|
2022-11-11 00:07:14 -08:00
|
|
|
Cypress.Commands.add('createFixtureWorkflow', (fixtureKey, workflowName) => {
|
2023-03-09 08:08:47 -08:00
|
|
|
const workflowPage = new WorkflowPage();
|
2022-11-11 00:07:14 -08:00
|
|
|
|
|
|
|
// We need to force the click because the input is hidden
|
2023-03-09 08:08:47 -08:00
|
|
|
workflowPage.getters
|
2022-12-15 07:39:59 -08:00
|
|
|
.workflowImportInput()
|
|
|
|
.selectFile(`cypress/fixtures/${fixtureKey}`, { force: true });
|
2023-03-16 02:19:12 -07:00
|
|
|
|
|
|
|
cy.waitForLoad(false);
|
2023-03-09 08:08:47 -08:00
|
|
|
workflowPage.actions.setWorkflowName(workflowName);
|
2022-11-11 00:07:14 -08:00
|
|
|
|
2023-03-09 08:08:47 -08:00
|
|
|
workflowPage.getters.saveButton().should('contain', 'Saved');
|
2022-12-15 07:39:59 -08:00
|
|
|
});
|
2022-11-11 00:07:14 -08:00
|
|
|
|
2022-12-15 07:39:59 -08:00
|
|
|
Cypress.Commands.add(
|
|
|
|
'findChildByTestId',
|
|
|
|
{ prevSubject: true },
|
|
|
|
(subject: Cypress.Chainable<JQuery<HTMLElement>>, childTestId) => {
|
|
|
|
return subject.find(`[data-test-id="${childTestId}"]`);
|
|
|
|
},
|
|
|
|
);
|
2022-11-11 00:07:14 -08:00
|
|
|
|
2023-03-16 02:19:12 -07:00
|
|
|
Cypress.Commands.add('waitForLoad', (waitForIntercepts = true) => {
|
2023-03-10 07:54:54 -08:00
|
|
|
// These aliases are set-up before each test in cypress/support/e2e.ts
|
|
|
|
// we can't set them up here because at this point it would be too late
|
|
|
|
// and the requests would already have been made
|
2023-04-28 03:02:28 -07:00
|
|
|
if (waitForIntercepts) {
|
|
|
|
cy.wait(['@loadSettings', '@loadLogin']);
|
2023-03-16 02:19:12 -07:00
|
|
|
}
|
2023-03-08 06:11:13 -08:00
|
|
|
cy.getByTestId('node-view-loader', { timeout: 20000 }).should('not.exist');
|
|
|
|
cy.get('.el-loading-mask', { timeout: 20000 }).should('not.exist');
|
2022-12-15 07:39:59 -08:00
|
|
|
});
|
2022-12-13 02:55:51 -08:00
|
|
|
|
2022-12-15 07:39:59 -08:00
|
|
|
Cypress.Commands.add('signin', ({ email, password }) => {
|
|
|
|
const signinPage = new SigninPage();
|
2023-03-09 06:26:27 -08:00
|
|
|
const workflowsPage = new WorkflowsPage();
|
2022-11-08 04:21:10 -08:00
|
|
|
|
2022-12-15 07:39:59 -08:00
|
|
|
cy.session(
|
|
|
|
[email, password],
|
|
|
|
() => {
|
2022-11-08 04:21:10 -08:00
|
|
|
cy.visit(signinPage.url);
|
|
|
|
|
2022-11-22 01:37:26 -08:00
|
|
|
signinPage.getters.form().within(() => {
|
|
|
|
signinPage.getters.email().type(email);
|
|
|
|
signinPage.getters.password().type(password);
|
|
|
|
signinPage.getters.submit().click();
|
2022-11-08 04:21:10 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
// we should be redirected to /workflows
|
2023-03-09 06:26:27 -08:00
|
|
|
cy.url().should('include', workflowsPage.url);
|
2022-11-08 04:21:10 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
validate() {
|
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('exist');
|
|
|
|
},
|
2022-12-15 07:39:59 -08:00
|
|
|
},
|
|
|
|
);
|
2022-11-08 04:21:10 -08:00
|
|
|
});
|
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
Cypress.Commands.add('signout', () => {
|
|
|
|
cy.visit('/signout');
|
|
|
|
cy.waitForLoad();
|
|
|
|
cy.url().should('include', '/signin');
|
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('not.exist');
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('signup', ({ firstName, lastName, password, url }) => {
|
|
|
|
const signupPage = new SignupPage();
|
|
|
|
|
|
|
|
cy.visit(url);
|
|
|
|
|
|
|
|
signupPage.getters.form().within(() => {
|
|
|
|
cy.url().then((url) => {
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.intercept('/rest/users/*').as('userSignup')
|
2023-02-08 12:41:35 -08:00
|
|
|
signupPage.getters.firstName().type(firstName);
|
|
|
|
signupPage.getters.lastName().type(lastName);
|
|
|
|
signupPage.getters.password().type(password);
|
|
|
|
signupPage.getters.submit().click();
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.wait('@userSignup');
|
2023-02-08 12:41:35 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-05-03 05:06:06 -07:00
|
|
|
Cypress.Commands.add('setup', ({ email, firstName, lastName, password }, skipIntercept = false) => {
|
2022-11-08 04:21:10 -08:00
|
|
|
const signupPage = new SignupPage();
|
|
|
|
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.intercept('GET', signupPage.url).as('setupPage');
|
2022-11-08 04:21:10 -08:00
|
|
|
cy.visit(signupPage.url);
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.wait('@setupPage');
|
2022-11-08 04:21:10 -08:00
|
|
|
|
2022-11-22 01:37:26 -08:00
|
|
|
signupPage.getters.form().within(() => {
|
2022-11-08 04:21:10 -08:00
|
|
|
cy.url().then((url) => {
|
2023-02-08 12:41:35 -08:00
|
|
|
if (url.includes(signupPage.url)) {
|
2022-11-22 01:37:26 -08:00
|
|
|
signupPage.getters.email().type(email);
|
|
|
|
signupPage.getters.firstName().type(firstName);
|
|
|
|
signupPage.getters.lastName().type(lastName);
|
|
|
|
signupPage.getters.password().type(password);
|
2023-05-03 05:06:06 -07:00
|
|
|
|
|
|
|
cy.intercept('POST', '/rest/owner/setup').as('setupRequest');
|
2022-11-22 01:37:26 -08:00
|
|
|
signupPage.getters.submit().click();
|
2023-05-03 05:06:06 -07:00
|
|
|
|
|
|
|
if(!skipIntercept) {
|
|
|
|
cy.wait('@setupRequest');
|
|
|
|
}
|
2022-11-08 04:21:10 -08:00
|
|
|
} else {
|
|
|
|
cy.log('User already signed up');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-12-15 07:39:59 -08:00
|
|
|
});
|
2022-11-24 03:52:09 -08:00
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
Cypress.Commands.add('interceptREST', (method, url) => {
|
|
|
|
cy.intercept(method, `http://localhost:5678/rest${url}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('inviteUsers', ({ instanceOwner, users }) => {
|
|
|
|
const settingsUsersPage = new SettingsUsersPage();
|
|
|
|
|
|
|
|
cy.signin(instanceOwner);
|
|
|
|
|
|
|
|
users.forEach((user) => {
|
|
|
|
cy.signin(instanceOwner);
|
|
|
|
cy.visit(settingsUsersPage.url);
|
|
|
|
|
|
|
|
cy.interceptREST('POST', '/users').as('inviteUser');
|
|
|
|
|
|
|
|
settingsUsersPage.getters.inviteButton().click();
|
|
|
|
settingsUsersPage.getters.inviteUsersModal().within((modal) => {
|
|
|
|
settingsUsersPage.getters.inviteUsersModalEmailsInput().type(user.email).type('{enter}');
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.wait('@inviteUser').then((interception) => {
|
|
|
|
const inviteLink = interception.response!.body.data[0].user.inviteAcceptUrl;
|
|
|
|
cy.log(JSON.stringify(interception.response!.body.data[0].user));
|
|
|
|
cy.log(inviteLink);
|
|
|
|
cy.signout();
|
|
|
|
cy.signup({ ...user, url: inviteLink });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-24 03:52:09 -08:00
|
|
|
Cypress.Commands.add('skipSetup', () => {
|
|
|
|
const signupPage = new SignupPage();
|
2023-03-08 06:11:13 -08:00
|
|
|
const workflowPage = new WorkflowPage();
|
2022-11-24 03:52:09 -08:00
|
|
|
const Confirmation = new MessageBox();
|
|
|
|
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.intercept('GET', signupPage.url).as('setupPage');
|
2022-11-24 03:52:09 -08:00
|
|
|
cy.visit(signupPage.url);
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.wait('@setupPage');
|
2022-11-24 03:52:09 -08:00
|
|
|
|
|
|
|
signupPage.getters.form().within(() => {
|
|
|
|
cy.url().then((url) => {
|
|
|
|
if (url.endsWith(signupPage.url)) {
|
|
|
|
signupPage.getters.skip().click();
|
|
|
|
|
|
|
|
Confirmation.getters.header().should('contain.text', 'Skip owner account setup?');
|
|
|
|
Confirmation.actions.confirm();
|
|
|
|
|
2023-03-08 06:11:13 -08:00
|
|
|
// we should be redirected to empty canvas
|
|
|
|
cy.intercept('GET', '/rest/workflows/new').as('loading');
|
|
|
|
cy.url().should('include', workflowPage.url);
|
|
|
|
cy.wait('@loading');
|
2022-11-24 03:52:09 -08:00
|
|
|
} else {
|
|
|
|
cy.log('User already signed up');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-12-15 07:39:59 -08:00
|
|
|
});
|
2022-11-28 09:11:33 -08:00
|
|
|
|
|
|
|
Cypress.Commands.add('resetAll', () => {
|
|
|
|
cy.task('reset');
|
|
|
|
Cypress.session.clearAllSavedSessions();
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('setupOwner', (payload) => {
|
|
|
|
cy.task('setup-owner', payload);
|
|
|
|
});
|
2022-12-05 05:31:14 -08:00
|
|
|
|
2023-01-04 00:47:48 -08:00
|
|
|
Cypress.Commands.add('enableFeature', (feature) => {
|
2023-05-03 05:06:06 -07:00
|
|
|
cy.task('set-feature', { feature, enabled: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('disableFeature', (feature) => {
|
|
|
|
cy.task('set-feature', { feature, enabled: false });
|
2023-01-04 00:47:48 -08:00
|
|
|
});
|
|
|
|
|
2022-12-07 09:16:38 -08:00
|
|
|
Cypress.Commands.add('grantBrowserPermissions', (...permissions: string[]) => {
|
2022-12-15 07:39:59 -08:00
|
|
|
if (Cypress.isBrowser('chrome')) {
|
|
|
|
cy.wrap(
|
|
|
|
Cypress.automation('remote:debugger:protocol', {
|
|
|
|
command: 'Browser.grantPermissions',
|
|
|
|
params: {
|
|
|
|
permissions,
|
|
|
|
origin: window.location.origin,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2022-12-07 09:16:38 -08:00
|
|
|
}
|
|
|
|
});
|
2023-03-02 07:50:21 -08:00
|
|
|
|
2023-03-09 08:08:47 -08:00
|
|
|
Cypress.Commands.add('readClipboard', () =>
|
|
|
|
cy.window().then((win) => win.navigator.clipboard.readText()),
|
|
|
|
);
|
2022-12-14 01:33:44 -08:00
|
|
|
|
2022-12-05 05:31:14 -08:00
|
|
|
Cypress.Commands.add('paste', { prevSubject: true }, (selector, pastePayload) => {
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
|
2022-12-15 07:39:59 -08:00
|
|
|
cy.wrap(selector).then(($destination) => {
|
2022-12-05 05:31:14 -08:00
|
|
|
const pasteEvent = Object.assign(new Event('paste', { bubbles: true, cancelable: true }), {
|
2022-12-15 07:39:59 -08:00
|
|
|
clipboardData: {
|
|
|
|
getData: () => pastePayload,
|
|
|
|
},
|
2022-12-05 05:31:14 -08:00
|
|
|
});
|
|
|
|
$destination[0].dispatchEvent(pasteEvent);
|
|
|
|
});
|
|
|
|
});
|
2022-12-14 01:33:44 -08:00
|
|
|
|
2023-04-21 06:37:09 -07:00
|
|
|
Cypress.Commands.add('drag', (selector, pos, options) => {
|
|
|
|
const index = options?.index || 0;
|
2023-02-06 20:47:37 -08:00
|
|
|
const [xDiff, yDiff] = pos;
|
2023-04-21 06:37:09 -07:00
|
|
|
const element = cy.get(selector).eq(index);
|
2022-12-14 01:33:44 -08:00
|
|
|
element.should('exist');
|
|
|
|
|
2023-04-21 06:37:09 -07:00
|
|
|
const originalLocation = Cypress.$(selector)[index].getBoundingClientRect();
|
2022-12-14 01:33:44 -08:00
|
|
|
|
|
|
|
element.trigger('mousedown');
|
|
|
|
element.trigger('mousemove', {
|
|
|
|
which: 1,
|
2023-04-28 03:02:28 -07:00
|
|
|
pageX: options?.abs ? xDiff : originalLocation.right + xDiff,
|
|
|
|
pageY: options?.abs ? yDiff : originalLocation.top + yDiff,
|
2022-12-14 01:33:44 -08:00
|
|
|
force: true,
|
|
|
|
});
|
2023-02-08 05:48:28 -08:00
|
|
|
element.trigger('mouseup', { force: true });
|
2022-12-14 01:33:44 -08:00
|
|
|
});
|
2023-02-06 20:47:37 -08:00
|
|
|
|
|
|
|
Cypress.Commands.add('draganddrop', (draggableSelector, droppableSelector) => {
|
2023-02-09 06:59:01 -08:00
|
|
|
if (draggableSelector) {
|
|
|
|
cy.get(draggableSelector).should('exist');
|
|
|
|
}
|
2023-02-06 20:47:37 -08:00
|
|
|
cy.get(droppableSelector).should('exist');
|
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
cy.get(droppableSelector)
|
|
|
|
.first()
|
|
|
|
.then(([$el]) => {
|
|
|
|
const coords = $el.getBoundingClientRect();
|
|
|
|
|
|
|
|
const pageX = coords.left + coords.width / 2;
|
|
|
|
const pageY = coords.top + coords.height / 2;
|
|
|
|
|
2023-02-09 06:59:01 -08:00
|
|
|
if (draggableSelector) {
|
|
|
|
// We can't use realMouseDown here because it hangs headless run
|
|
|
|
cy.get(draggableSelector).trigger('mousedown');
|
|
|
|
}
|
2023-02-08 12:41:35 -08:00
|
|
|
// We don't chain these commands to make sure cy.get is re-trying correctly
|
|
|
|
cy.get(droppableSelector).realMouseMove(pageX, pageY);
|
|
|
|
cy.get(droppableSelector).realHover();
|
|
|
|
cy.get(droppableSelector).realMouseUp();
|
2023-02-09 06:59:01 -08:00
|
|
|
if (draggableSelector) {
|
|
|
|
cy.get(draggableSelector).realMouseUp();
|
|
|
|
}
|
2023-02-08 12:41:35 -08:00
|
|
|
});
|
2023-02-06 20:47:37 -08:00
|
|
|
});
|