2023-02-08 12:41:35 -08:00
|
|
|
import 'cypress-real-events';
|
2023-06-22 15:38:12 -07:00
|
|
|
import { WorkflowPage } from '../pages';
|
|
|
|
import { BASE_URL, N8N_AUTH_COOKIE } from '../constants';
|
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) {
|
2023-06-22 15:38:12 -07:00
|
|
|
cy.wait(['@loadSettings']);
|
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 }) => {
|
2023-06-22 15:38:12 -07:00
|
|
|
Cypress.session.clearAllSavedSessions();
|
|
|
|
cy.session([email, password], () => cy.request('POST', '/rest/login', { email, password }), {
|
|
|
|
validate() {
|
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('exist');
|
2022-12-15 07:39:59 -08:00
|
|
|
},
|
2023-06-22 15:38:12 -07:00
|
|
|
});
|
2022-11-08 04:21:10 -08:00
|
|
|
});
|
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
Cypress.Commands.add('signout', () => {
|
2023-06-22 15:38:12 -07:00
|
|
|
cy.request('POST', '/rest/logout');
|
2023-02-08 12:41:35 -08:00
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('not.exist');
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('interceptREST', (method, url) => {
|
|
|
|
cy.intercept(method, `http://localhost:5678/rest${url}`);
|
|
|
|
});
|
|
|
|
|
2023-06-22 15:38:12 -07:00
|
|
|
const setFeature = (feature: string, enabled: boolean) =>
|
|
|
|
cy.request('PATCH', `${BASE_URL}/rest/e2e/feature`, { feature: `feat:${feature}`, enabled });
|
2023-05-03 05:06:06 -07:00
|
|
|
|
2023-06-22 15:38:12 -07:00
|
|
|
Cypress.Commands.add('enableFeature', (feature: string) => setFeature(feature, true));
|
|
|
|
Cypress.Commands.add('disableFeature', (feature): string => setFeature(feature, 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
|
|
|
|
2023-07-14 06:36:17 -07:00
|
|
|
element.trigger('mousedown', { force: true });
|
2022-12-14 01:33:44 -08:00
|
|
|
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
|
|
|
});
|