2023-02-08 12:41:35 -08:00
|
|
|
import 'cypress-real-events';
|
2024-06-11 01:23:30 -07:00
|
|
|
import FakeTimers from '@sinonjs/fake-timers';
|
2024-06-11 05:45:15 -07:00
|
|
|
import type { IN8nUISettings } from 'n8n-workflow';
|
2023-06-22 15:38:12 -07:00
|
|
|
import { WorkflowPage } from '../pages';
|
2024-01-08 01:35:18 -08:00
|
|
|
import {
|
|
|
|
BACKEND_BASE_URL,
|
|
|
|
INSTANCE_ADMIN,
|
|
|
|
INSTANCE_MEMBERS,
|
|
|
|
INSTANCE_OWNER,
|
|
|
|
N8N_AUTH_COOKIE,
|
|
|
|
} from '../constants';
|
2024-06-12 23:39:53 -07:00
|
|
|
import { getUniqueWorkflowName } from '../utils/workflowUtils';
|
2022-11-08 04:21:10 -08:00
|
|
|
|
2024-06-11 01:23:30 -07:00
|
|
|
Cypress.Commands.add('setAppDate', (targetDate: number | Date) => {
|
|
|
|
cy.window().then((win) => {
|
|
|
|
FakeTimers.withGlobal(win).install({
|
|
|
|
now: targetDate,
|
|
|
|
toFake: ['Date'],
|
|
|
|
shouldAdvanceTime: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2024-06-12 23:39:53 -07:00
|
|
|
Cypress.Commands.add(
|
|
|
|
'createFixtureWorkflow',
|
|
|
|
(fixtureKey: string, workflowName = getUniqueWorkflowName()) => {
|
|
|
|
const workflowPage = new WorkflowPage();
|
2022-11-11 00:07:14 -08:00
|
|
|
|
2024-06-12 23:39:53 -07:00
|
|
|
// We need to force the click because the input is hidden
|
|
|
|
workflowPage.getters
|
|
|
|
.workflowImportInput()
|
|
|
|
.selectFile(`fixtures/${fixtureKey}`, { force: true });
|
2023-03-16 02:19:12 -07:00
|
|
|
|
2024-06-12 23:39:53 -07:00
|
|
|
cy.waitForLoad(false);
|
|
|
|
workflowPage.actions.setWorkflowName(workflowName);
|
|
|
|
workflowPage.getters.saveButton().should('contain', 'Saved');
|
|
|
|
workflowPage.actions.zoomToFit();
|
|
|
|
},
|
|
|
|
);
|
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-11-03 07:22:37 -07:00
|
|
|
cy.wait(['@loadSettings', '@loadNodeTypes']);
|
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 }) => {
|
2024-06-10 06:49:50 -07:00
|
|
|
void Cypress.session.clearAllSavedSessions();
|
2023-08-23 19:59:16 -07:00
|
|
|
cy.session([email, password], () =>
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `${BACKEND_BASE_URL}/rest/login`,
|
|
|
|
body: { email, password },
|
|
|
|
failOnStatusCode: false,
|
|
|
|
}),
|
2023-07-21 02:48:23 -07:00
|
|
|
);
|
2022-11-08 04:21:10 -08:00
|
|
|
});
|
|
|
|
|
2024-06-11 05:45:15 -07:00
|
|
|
Cypress.Commands.add('signinAsOwner', () => cy.signin(INSTANCE_OWNER));
|
|
|
|
Cypress.Commands.add('signinAsAdmin', () => cy.signin(INSTANCE_ADMIN));
|
|
|
|
Cypress.Commands.add('signinAsMember', (index = 0) => cy.signin(INSTANCE_MEMBERS[index]));
|
2024-01-08 01:35:18 -08:00
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
Cypress.Commands.add('signout', () => {
|
2024-04-09 02:20:35 -07:00
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `${BACKEND_BASE_URL}/rest/logout`,
|
2024-05-17 01:53:15 -07:00
|
|
|
headers: { 'browser-id': localStorage.getItem('n8n-browserId') },
|
2024-04-09 02:20:35 -07:00
|
|
|
});
|
2023-02-08 12:41:35 -08:00
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('not.exist');
|
|
|
|
});
|
|
|
|
|
2024-06-11 05:45:15 -07:00
|
|
|
export let settings: Partial<IN8nUISettings>;
|
|
|
|
Cypress.Commands.add('overrideSettings', (value: Partial<IN8nUISettings>) => {
|
|
|
|
settings = value;
|
2023-02-08 12:41:35 -08:00
|
|
|
});
|
|
|
|
|
2023-06-22 15:38:12 -07:00
|
|
|
const setFeature = (feature: string, enabled: boolean) =>
|
2023-07-21 02:48:23 -07:00
|
|
|
cy.request('PATCH', `${BACKEND_BASE_URL}/rest/e2e/feature`, {
|
|
|
|
feature: `feat:${feature}`,
|
|
|
|
enabled,
|
|
|
|
});
|
2023-05-03 05:06:06 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const setQuota = (feature: string, value: number) =>
|
|
|
|
cy.request('PATCH', `${BACKEND_BASE_URL}/rest/e2e/quota`, {
|
|
|
|
feature: `quota:${feature}`,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
|
2023-11-10 14:48:31 -08:00
|
|
|
const setQueueMode = (enabled: boolean) =>
|
|
|
|
cy.request('PATCH', `${BACKEND_BASE_URL}/rest/e2e/queue-mode`, {
|
|
|
|
enabled,
|
|
|
|
});
|
|
|
|
|
2023-06-22 15:38:12 -07:00
|
|
|
Cypress.Commands.add('enableFeature', (feature: string) => setFeature(feature, true));
|
2024-05-17 01:53:15 -07:00
|
|
|
Cypress.Commands.add('changeQuota', (feature: string, value: number) => setQuota(feature, value));
|
2023-11-10 14:48:31 -08:00
|
|
|
Cypress.Commands.add('disableFeature', (feature: string) => setFeature(feature, false));
|
|
|
|
Cypress.Commands.add('enableQueueMode', () => setQueueMode(true));
|
|
|
|
Cypress.Commands.add('disableQueueMode', () => setQueueMode(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) => {
|
2024-06-10 06:49:50 -07:00
|
|
|
const index = options?.index ?? 0;
|
2023-02-06 20:47:37 -08:00
|
|
|
const [xDiff, yDiff] = pos;
|
2023-07-31 03:32:08 -07:00
|
|
|
const element = typeof selector === 'string' ? cy.get(selector).eq(index) : selector;
|
2022-12-14 01:33:44 -08:00
|
|
|
element.should('exist');
|
|
|
|
|
2023-07-31 03:32:08 -07:00
|
|
|
element.then(([$el]) => {
|
|
|
|
const originalLocation = $el.getBoundingClientRect();
|
|
|
|
const newPosition = {
|
|
|
|
x: options?.abs ? xDiff : originalLocation.right + xDiff,
|
|
|
|
y: options?.abs ? yDiff : originalLocation.top + yDiff,
|
2023-08-16 08:13:57 -07:00
|
|
|
};
|
|
|
|
if (options?.realMouse) {
|
2023-07-31 03:32:08 -07:00
|
|
|
element.realMouseDown();
|
|
|
|
element.realMouseMove(newPosition.x, newPosition.y);
|
|
|
|
element.realMouseUp();
|
|
|
|
} else {
|
2023-08-16 08:13:57 -07:00
|
|
|
element.trigger('mousedown', { force: true });
|
2023-07-31 03:32:08 -07:00
|
|
|
element.trigger('mousemove', {
|
|
|
|
which: 1,
|
|
|
|
pageX: newPosition.x,
|
|
|
|
pageY: newPosition.y,
|
|
|
|
force: true,
|
|
|
|
});
|
2023-08-02 03:48:55 -07:00
|
|
|
if (options?.clickToFinish) {
|
|
|
|
// Click to finish the drag
|
|
|
|
// For some reason, mouseup isn't working when moving nodes
|
|
|
|
cy.get('body').click(newPosition.x, newPosition.y);
|
|
|
|
} else {
|
2023-08-16 08:13:57 -07:00
|
|
|
element.trigger('mouseup', { force: true });
|
2023-08-02 03:48:55 -07:00
|
|
|
}
|
2023-07-31 03:32:08 -07:00
|
|
|
}
|
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
|
2024-01-04 08:23:24 -08:00
|
|
|
cy.get(droppableSelector).realMouseMove(0, 0);
|
2023-02-08 12:41:35 -08:00
|
|
|
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
|
|
|
});
|
2023-10-30 05:44:19 -07:00
|
|
|
|
2023-11-28 07:47:28 -08:00
|
|
|
Cypress.Commands.add('push', (type, data) => {
|
|
|
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/push`, {
|
|
|
|
type,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-30 05:44:19 -07:00
|
|
|
Cypress.Commands.add('shouldNotHaveConsoleErrors', () => {
|
|
|
|
cy.window().then((win) => {
|
|
|
|
const spy = cy.spy(win.console, 'error');
|
|
|
|
cy.wrap(spy).should('not.have.been.called');
|
|
|
|
});
|
|
|
|
});
|
2024-01-08 01:35:18 -08:00
|
|
|
|
|
|
|
Cypress.Commands.add('resetDatabase', () => {
|
|
|
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
|
|
|
owner: INSTANCE_OWNER,
|
|
|
|
members: INSTANCE_MEMBERS,
|
|
|
|
admin: INSTANCE_ADMIN,
|
|
|
|
});
|
|
|
|
});
|