test: Add e2e tests for cred setup on workflow editor (no-changelog) (#8245)

## Summary

Follow-up to https://github.com/n8n-io/n8n/pull/8240

Adds e2e tests for the template credential setup in workflow editor


## Related tickets and issues

https://linear.app/n8n/issue/ADO-1463/feature-enable-users-to-close-and-re-open-the-setup
This commit is contained in:
Tomi Turtiainen
2024-01-08 11:35:18 +02:00
committed by GitHub
parent 3cf6704dbb
commit 008fd5a917
9 changed files with 144 additions and 42 deletions

View File

@@ -6,6 +6,9 @@ import {
import * as templateCredentialsSetupPage from '../pages/template-credential-setup';
import { TemplateWorkflowPage } from '../pages/template-workflow';
import { WorkflowPage } from '../pages/workflow';
import * as formStep from '../composables/setup-template-form-step';
import { getSetupWorkflowCredentialsButton } from '../composables/setup-workflow-credentials-button';
import * as setupCredsModal from '../composables/modals/workflow-credential-setup-modal';
const templateWorkflowPage = new TemplateWorkflowPage();
const workflowPage = new WorkflowPage();
@@ -69,13 +72,9 @@ describe('Template credentials setup', () => {
'The credential you select will be used in the Telegram node of the workflow template.',
];
templateCredentialsSetupPage.getters.appCredentialSteps().each(($el, index) => {
templateCredentialsSetupPage.getters
.stepHeading($el)
.should('have.text', expectedAppNames[index]);
templateCredentialsSetupPage.getters
.stepDescription($el)
.should('have.text', expectedAppDescriptions[index]);
formStep.getFormStep().each(($el, index) => {
formStep.getStepHeading($el).should('have.text', expectedAppNames[index]);
formStep.getStepDescription($el).should('have.text', expectedAppDescriptions[index]);
});
});
@@ -100,10 +99,7 @@ describe('Template credentials setup', () => {
templateCredentialsSetupPage.fillInDummyCredentialsForAppWithConfirm('X (Formerly Twitter)');
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Telegram');
cy.intercept('POST', '/rest/workflows').as('createWorkflow');
templateCredentialsSetupPage.getters.continueButton().should('be.enabled');
templateCredentialsSetupPage.getters.continueButton().click();
cy.wait('@createWorkflow');
templateCredentialsSetupPage.finishCredentialSetup();
workflowPage.getters.canvasNodes().should('have.length', 3);
@@ -137,13 +133,9 @@ describe('Template credentials setup', () => {
'The credential you select will be used in the Nextcloud node of the workflow template.',
];
templateCredentialsSetupPage.getters.appCredentialSteps().each(($el, index) => {
templateCredentialsSetupPage.getters
.stepHeading($el)
.should('have.text', expectedAppNames[index]);
templateCredentialsSetupPage.getters
.stepDescription($el)
.should('have.text', expectedAppDescriptions[index]);
formStep.getFormStep().each(($el, index) => {
formStep.getStepHeading($el).should('have.text', expectedAppNames[index]);
formStep.getStepDescription($el).should('have.text', expectedAppDescriptions[index]);
});
templateCredentialsSetupPage.getters.continueButton().should('be.disabled');
@@ -151,11 +143,68 @@ describe('Template credentials setup', () => {
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Email (IMAP)');
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Nextcloud');
cy.intercept('POST', '/rest/workflows').as('createWorkflow');
templateCredentialsSetupPage.getters.continueButton().should('be.enabled');
templateCredentialsSetupPage.getters.continueButton().click();
cy.wait('@createWorkflow');
templateCredentialsSetupPage.finishCredentialSetup();
workflowPage.getters.canvasNodes().should('have.length', 3);
});
describe('Credential setup from workflow editor', () => {
beforeEach(() => {
cy.resetDatabase();
cy.signinAsOwner();
});
it('should allow credential setup from workflow editor if user skips it during template setup', () => {
templateCredentialsSetupPage.visitTemplateCredentialSetupPage(testTemplate.id);
templateCredentialsSetupPage.getters.skipLink().click();
getSetupWorkflowCredentialsButton().should('be.visible');
// We need to save the workflow or otherwise a browser native popup
// will block cypress from continuing
workflowPage.actions.saveWorkflowOnButtonClick();
});
it('should allow credential setup from workflow editor if user fills in credentials partially during template setup', () => {
templateCredentialsSetupPage.visitTemplateCredentialSetupPage(testTemplate.id);
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Shopify');
templateCredentialsSetupPage.finishCredentialSetup();
getSetupWorkflowCredentialsButton().should('be.visible');
});
it('should fill credentials from workflow editor', () => {
templateCredentialsSetupPage.visitTemplateCredentialSetupPage(testTemplate.id);
templateCredentialsSetupPage.getters.skipLink().click();
getSetupWorkflowCredentialsButton().click();
setupCredsModal.getWorkflowCredentialsModal().should('be.visible');
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Shopify');
templateCredentialsSetupPage.fillInDummyCredentialsForAppWithConfirm('X (Formerly Twitter)');
templateCredentialsSetupPage.fillInDummyCredentialsForApp('Telegram');
setupCredsModal.closeModal();
// Focus the canvas so the copy to clipboard works
workflowPage.getters.canvasNodes().eq(0).realClick();
workflowPage.actions.selectAll();
workflowPage.actions.hitCopy();
cy.grantBrowserPermissions('clipboardReadWrite', 'clipboardSanitizedWrite');
// Check workflow JSON by copying it to clipboard
cy.readClipboard().then((workflowJSON) => {
const workflow = JSON.parse(workflowJSON);
workflow.nodes.forEach((node: any) => {
expect(Object.keys(node.credentials ?? {})).to.have.lengthOf(1);
});
});
// We need to save the workflow or otherwise a browser native popup
// will block cypress from continuing
workflowPage.actions.saveWorkflowOnButtonClick();
});
});
});