From ac2f89a18a4c25ef1b39bcacc624884de9197fdf Mon Sep 17 00:00:00 2001 From: OlegIvaniv Date: Thu, 9 Mar 2023 15:22:12 +0100 Subject: [PATCH] feat(editor): Do not automatically add manual trigger on node plus (#5644) * feat(editor): Do not add manual trigger node if node creator trigger via canvas actions * Add e2e tests * Install cypress-plugin-tab, do not use cy.realPress as it hangs the tests * Exclude tab tests --- cypress/e2e/4-node-creator.cy.ts | 47 +++++++++++++++++++ cypress/pages/workflow.ts | 4 ++ cypress/support/commands.ts | 2 +- packages/editor-ui/src/Interface.ts | 11 +++++ .../src/components/Node/NodeCreation.vue | 12 ++++- packages/editor-ui/src/constants.ts | 16 +++++++ packages/editor-ui/src/stores/nodeCreator.ts | 27 +++++++++-- packages/editor-ui/src/views/NodeView.vue | 30 +++++++----- 8 files changed, 131 insertions(+), 18 deletions(-) diff --git a/cypress/e2e/4-node-creator.cy.ts b/cypress/e2e/4-node-creator.cy.ts index 2054209f4f..014e94aece 100644 --- a/cypress/e2e/4-node-creator.cy.ts +++ b/cypress/e2e/4-node-creator.cy.ts @@ -144,4 +144,51 @@ describe('Node Creator', () => { .click(); secondParameter().find('input.el-input__inner').should('have.value', 'option4'); }); + + describe('should correctly append manual trigger for regular actions', () => { + // For these sources, manual node should be added + const sourcesWithAppend = [ + { + name: 'canvas add button', + handler: () => nodeCreatorFeature.getters.canvasAddButton().click(), + }, { + name: 'plus button', + handler: () => nodeCreatorFeature.getters.plusButton().click(), + }, + // We can't test this one because it's not possible to trigger tab key in Cypress + // only way is to use `realPress` which is hanging the tests in Electron for some reason + // { + // name: 'tab key', + // handler: () => cy.realPress('Tab'), + // }, + ] + sourcesWithAppend.forEach((source) => { + it(`should append manual trigger when source is ${source.name}`, () => { + source.handler() + nodeCreatorFeature.getters.searchBar().find('input').clear().type('n8n'); + nodeCreatorFeature.getters.getCreatorItem('n8n').click(); + nodeCreatorFeature.getters.getCreatorItem('Create a credential').click(); + NDVModal.actions.close(); + WorkflowPage.getters.canvasNodes().should('have.length', 2); + }); + }); + + it('should not append manual trigger when source is canvas related', () => { + nodeCreatorFeature.getters.canvasAddButton().click(); + nodeCreatorFeature.getters.searchBar().find('input').clear().type('n8n'); + nodeCreatorFeature.getters.getCreatorItem('n8n').click(); + nodeCreatorFeature.getters.getCreatorItem('Create a credential').click(); + NDVModal.actions.close(); + WorkflowPage.actions.deleteNode('When clicking "Execute Workflow"') + WorkflowPage.getters.canvasNodePlusEndpointByName('n8n').click() + nodeCreatorFeature.getters.searchBar().find('input').clear().type('n8n'); + nodeCreatorFeature.getters.getCreatorItem('n8n').click(); + nodeCreatorFeature.getters.getCreatorItem('Create a credential').click(); + NDVModal.actions.close(); + WorkflowPage.getters.canvasNodes().should('have.length', 2); + WorkflowPage.actions.zoomToFit(); + WorkflowPage.actions.addNodeBetweenNodes('n8n', 'n8n1', 'Item Lists') + WorkflowPage.getters.canvasNodes().should('have.length', 3); + }) + }); }); diff --git a/cypress/pages/workflow.ts b/cypress/pages/workflow.ts index 2dc647e4bf..4ad4b753a9 100644 --- a/cypress/pages/workflow.ts +++ b/cypress/pages/workflow.ts @@ -174,6 +174,10 @@ export class WorkflowPage extends BasePage { saveWorkflowUsingKeyboardShortcut: () => { cy.get('body').type('{meta}', { release: false }).type('s'); }, + deleteNode: (name: string) => { + this.getters.canvasNodeByName(name).first().click(); + cy.get('body').type('{del}'); + }, setWorkflowName: (name: string) => { this.getters.workflowNameInput().should('be.disabled'); this.getters.workflowNameInput().parent().click(); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 233c74ee55..f700b3c6f3 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -24,7 +24,7 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) import 'cypress-real-events'; -import { WorkflowsPage, SigninPage, SignupPage, SettingsUsersPage, WorkflowPage } from '../pages'; +import { SigninPage, SignupPage, SettingsUsersPage, WorkflowPage } from '../pages'; import { N8N_AUTH_COOKIE } from '../constants'; import { WorkflowPage as WorkflowPageClass } from '../pages/workflow'; import { MessageBox } from '../pages/modals/message-box'; diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 8503e38759..8f1021a22d 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -1179,11 +1179,22 @@ export type IFakeDoorLocation = export type INodeFilterType = typeof REGULAR_NODE_FILTER | typeof TRIGGER_NODE_FILTER; +export type NodeCreatorOpenSource = + | '' + | 'no_trigger_execution_tooltip' + | 'plus_endpoint' + | 'trigger_placeholder_button' + | 'tab' + | 'node_connection_action' + | 'node_connection_drop' + | 'add_node_button'; + export interface INodeCreatorState { itemsFilter: string; showScrim: boolean; rootViewHistory: INodeFilterType[]; selectedView: INodeFilterType; + openSource: NodeCreatorOpenSource; } export interface ISettingsState { diff --git a/packages/editor-ui/src/components/Node/NodeCreation.vue b/packages/editor-ui/src/components/Node/NodeCreation.vue index 58f4948226..edae0d921b 100644 --- a/packages/editor-ui/src/components/Node/NodeCreation.vue +++ b/packages/editor-ui/src/components/Node/NodeCreation.vue @@ -38,7 +38,12 @@