2023-02-08 12:41:35 -08:00
|
|
|
import 'cypress-real-events';
|
2023-06-22 15:38:12 -07:00
|
|
|
import { WorkflowPage } from '../pages';
|
2023-07-21 02:48:23 -07:00
|
|
|
import { BACKEND_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);
|
|
|
|
workflowPage.getters.saveButton().should('contain', 'Saved');
|
2023-11-03 07:22:37 -07:00
|
|
|
workflowPage.actions.zoomToFit();
|
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-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 }) => {
|
2023-06-22 15:38:12 -07:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2023-02-08 12:41:35 -08:00
|
|
|
Cypress.Commands.add('signout', () => {
|
2023-07-28 00:51:07 -07:00
|
|
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/logout`);
|
2023-02-08 12:41:35 -08:00
|
|
|
cy.getCookie(N8N_AUTH_COOKIE).should('not.exist');
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('interceptREST', (method, url) => {
|
2023-07-28 00:51:07 -07:00
|
|
|
cy.intercept(method, `${BACKEND_BASE_URL}/rest${url}`);
|
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
|
|
|
|
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-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
|
|
|
|
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
|
|
|
|
|
|
|
Cypress.Commands.add('shouldNotHaveConsoleErrors', () => {
|
|
|
|
cy.window().then((win) => {
|
|
|
|
const spy = cy.spy(win.console, 'error');
|
|
|
|
cy.wrap(spy).should('not.have.been.called');
|
|
|
|
});
|
|
|
|
});
|