Skip to content

Commit

Permalink
fix(editor): Fix workflow moving E2E tests (#13396)
Browse files Browse the repository at this point in the history
Co-authored-by: Danny Martini <danny@n8n.io>
  • Loading branch information
cstuncsik and despairblue authored Feb 20, 2025
1 parent ca76ef4 commit 073b05b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
45 changes: 30 additions & 15 deletions cypress/e2e/39-projects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ describe('Projects', { disableAutoLogin: true }, () => {
});

it('should move resources between projects', () => {
cy.intercept('GET', /\/rest\/(workflows|credentials).*/).as('getResources');

cy.signinAsOwner();
cy.visit(workflowsPage.url);

// Create a workflow and a credential in the Home project
cy.log('Create a workflow and a credential in the Home project');
workflowsPage.getters.workflowCards().should('not.have.length');
workflowsPage.getters.newWorkflowButtonCard().click();
projects.createWorkflow('Test_workflow_1.json', 'Workflow in Home project');
Expand All @@ -238,12 +240,12 @@ describe('Projects', { disableAutoLogin: true }, () => {
projects.getProjectTabCredentials().should('be.visible').click();
credentialsPage.getters.emptyListCreateCredentialButton().click();
projects.createCredential('Credential in Home project');

clearNotifications();

// Create a project and add a credential and a workflow to it
cy.log('Create a project and add a credential and a workflow to it');
projects.createProject('Project 1');
clearNotifications();

projects.getProjectTabCredentials().click();
credentialsPage.getters.emptyListCreateCredentialButton().click();
projects.createCredential('Credential in Project 1');
Expand All @@ -252,12 +254,12 @@ describe('Projects', { disableAutoLogin: true }, () => {
projects.getProjectTabWorkflows().click();
workflowsPage.getters.newWorkflowButtonCard().click();
projects.createWorkflow('Test_workflow_1.json', 'Workflow in Project 1');

clearNotifications();

// Create another project and add a credential and a workflow to it
cy.log('Create another project and add a credential and a workflow to it');
projects.createProject('Project 2');
clearNotifications();

projects.getProjectTabCredentials().click();
credentialsPage.getters.emptyListCreateCredentialButton().click();
projects.createCredential('Credential in Project 2');
Expand All @@ -268,7 +270,7 @@ describe('Projects', { disableAutoLogin: true }, () => {
projects.createWorkflow('Test_workflow_1.json', 'Workflow in Project 2');
clearNotifications();

// Move the workflow Personal from Home to Project 1
cy.log('Move the workflow Personal from Home to Project 1');
projects.getHomeButton().click();
workflowsPage.getters
.workflowCards()
Expand All @@ -291,14 +293,15 @@ describe('Projects', { disableAutoLogin: true }, () => {
.click();
projects.getResourceMoveModal().contains('button', 'Move workflow').click();
clearNotifications();
cy.wait('@getResources');

workflowsPage.getters
.workflowCards()
.should('have.length', 3)
.filter(':contains("Personal")')
.should('not.exist');

// Move the workflow from Project 1 to Project 2
cy.log('Move the workflow from Project 1 to Project 2');
projects.getMenuItems().first().click();
workflowsPage.getters.workflowCards().should('have.length', 2);
workflowsPage.getters.workflowCardActions('Workflow in Home project').click();
Expand All @@ -316,13 +319,13 @@ describe('Projects', { disableAutoLogin: true }, () => {
.filter(':contains("Project 2")')
.click();
projects.getResourceMoveModal().contains('button', 'Move workflow').click();
clearNotifications();

// Move the workflow from Project 2 to a member user
cy.log('Move the workflow from Project 2 to a member user');
projects.getMenuItems().last().click();
workflowsPage.getters.workflowCards().should('have.length', 2);
workflowsPage.getters.workflowCardActions('Workflow in Home project').click();
workflowsPage.getters.workflowMoveButton().click();
clearNotifications();

projects
.getResourceMoveModal()
Expand All @@ -337,9 +340,12 @@ describe('Projects', { disableAutoLogin: true }, () => {
.click();

projects.getResourceMoveModal().contains('button', 'Move workflow').click();
clearNotifications();
cy.wait('@getResources');

workflowsPage.getters.workflowCards().should('have.length', 1);

// Move the workflow from member user back to Home
cy.log('Move the workflow from member user back to Home');
projects.getHomeButton().click();
workflowsPage.getters
.workflowCards()
Expand All @@ -363,13 +369,15 @@ describe('Projects', { disableAutoLogin: true }, () => {

projects.getResourceMoveModal().contains('button', 'Move workflow').click();
clearNotifications();
cy.wait('@getResources');

workflowsPage.getters
.workflowCards()
.should('have.length', 3)
.filter(':contains("Personal")')
.should('have.length', 1);

// Move the credential from Project 1 to Project 2
cy.log('Move the credential from Project 1 to Project 2');
projects.getMenuItems().first().click();
projects.getProjectTabCredentials().click();
credentialsPage.getters.credentialCards().should('have.length', 1);
Expand All @@ -389,9 +397,11 @@ describe('Projects', { disableAutoLogin: true }, () => {
.click();
projects.getResourceMoveModal().contains('button', 'Move credential').click();
clearNotifications();
cy.wait('@getResources');

credentialsPage.getters.credentialCards().should('not.have.length');

// Move the credential from Project 2 to admin user
cy.log('Move the credential from Project 2 to admin user');
projects.getMenuItems().last().click();
projects.getProjectTabCredentials().click();
credentialsPage.getters.credentialCards().should('have.length', 2);
Expand All @@ -411,9 +421,12 @@ describe('Projects', { disableAutoLogin: true }, () => {
.filter(`:contains("${INSTANCE_ADMIN.email}")`)
.click();
projects.getResourceMoveModal().contains('button', 'Move credential').click();
clearNotifications();
cy.wait('@getResources');

credentialsPage.getters.credentialCards().should('have.length', 1);

// Move the credential from admin user back to instance owner
cy.log('Move the credential from admin user back to instance owner');
projects.getHomeButton().click();
projects.getProjectTabCredentials().click();
credentialsPage.getters.credentialCards().should('have.length', 3);
Expand All @@ -432,17 +445,18 @@ describe('Projects', { disableAutoLogin: true }, () => {
.should('have.length', 5)
.filter(`:contains("${INSTANCE_OWNER.email}")`)
.click();
projects.getResourceMoveModal().contains('button', 'Move credential').click();

projects.getResourceMoveModal().contains('button', 'Move credential').click();
clearNotifications();
cy.wait('@getResources');

credentialsPage.getters
.credentialCards()
.should('have.length', 3)
.filter(':contains("Personal")')
.should('have.length', 2);

// Move the credential from admin user back to its original project (Project 1)
cy.log('Move the credential from admin user back to its original project (Project 1)');
credentialsPage.getters.credentialCardActions('Credential in Project 1').click();
credentialsPage.getters.credentialMoveButton().click();

Expand All @@ -458,6 +472,7 @@ describe('Projects', { disableAutoLogin: true }, () => {
.filter(':contains("Project 1")')
.click();
projects.getResourceMoveModal().contains('button', 'Move credential').click();
clearNotifications();

projects.getMenuItems().first().click();
projects.getProjectTabCredentials().click();
Expand Down
10 changes: 6 additions & 4 deletions cypress/pages/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export const infoToast = () => cy.get('.el-notification:has(.el-notification--in
* Actions
*/
export const clearNotifications = () => {
const buttons = successToast().find('.el-notification__closeBtn');
buttons.then(($buttons) => {
if ($buttons.length) {
buttons.click({ multiple: true });
const notificationSelector = '.el-notification:has(.el-notification--success)';
cy.get('body').then(($body) => {
if ($body.find(notificationSelector).length) {
cy.get(notificationSelector)
.find('.el-notification__closeBtn')
.click({ multiple: true, force: true });
}
});
};

0 comments on commit 073b05b

Please sign in to comment.