diff --git a/cypress/e2e/5-ndv.cy.ts b/cypress/e2e/5-ndv.cy.ts index 89647eee6c..1aea7035f5 100644 --- a/cypress/e2e/5-ndv.cy.ts +++ b/cypress/e2e/5-ndv.cy.ts @@ -660,16 +660,19 @@ describe('NDV', () => { }); it('Stop listening for trigger event from NDV', () => { + cy.intercept('POST', '/rest/workflows/run').as('workflowRun'); workflowPage.actions.addInitialNodeToCanvas('Local File Trigger', { keepNdvOpen: true, action: 'On Changes To A Specific File', isTrigger: true, }); ndv.getters.triggerPanelExecuteButton().should('exist'); - ndv.getters.triggerPanelExecuteButton().click(); + ndv.getters.triggerPanelExecuteButton().realClick(); ndv.getters.triggerPanelExecuteButton().should('contain', 'Stop Listening'); - ndv.getters.triggerPanelExecuteButton().click(); - ndv.getters.triggerPanelExecuteButton().should('contain', 'Test step'); - workflowPage.getters.successToast().should('exist'); + ndv.getters.triggerPanelExecuteButton().realClick(); + cy.wait('@workflowRun').then(() => { + ndv.getters.triggerPanelExecuteButton().should('contain', 'Test step'); + workflowPage.getters.successToast().should('exist'); + }); }); }); diff --git a/packages/editor-ui/src/components/Node/NodeCreator/__tests__/useActions.test.ts b/packages/editor-ui/src/components/Node/NodeCreator/__tests__/useActions.test.ts index d041911d67..14a03254e1 100644 --- a/packages/editor-ui/src/components/Node/NodeCreator/__tests__/useActions.test.ts +++ b/packages/editor-ui/src/components/Node/NodeCreator/__tests__/useActions.test.ts @@ -1,6 +1,7 @@ import { setActivePinia } from 'pinia'; import { createTestingPinia } from '@pinia/testing'; import { useNodeCreatorStore } from '@/stores/nodeCreator.store'; +import { useNodeTypesStore } from '@/stores/nodeTypes.store'; import { useWorkflowsStore } from '@/stores/workflows.store'; import { useActions } from '../composables/useActions'; import { @@ -9,8 +10,10 @@ import { NODE_CREATOR_OPEN_SOURCES, NO_OP_NODE_TYPE, SCHEDULE_TRIGGER_NODE_TYPE, + SLACK_NODE_TYPE, SPLIT_IN_BATCHES_NODE_TYPE, TRIGGER_NODE_CREATOR_VIEW, + WEBHOOK_NODE_TYPE, } from '@/constants'; describe('useActions', () => { @@ -89,5 +92,85 @@ describe('useActions', () => { ], }); }); + + test('should connect node to schedule trigger when adding them together', () => { + const workflowsStore = useWorkflowsStore(); + const nodeCreatorStore = useNodeCreatorStore(); + const nodeTypesStore = useNodeTypesStore(); + + vi.spyOn(workflowsStore, 'workflowTriggerNodes', 'get').mockReturnValue([ + { type: SCHEDULE_TRIGGER_NODE_TYPE } as never, + ]); + vi.spyOn(nodeCreatorStore, 'openSource', 'get').mockReturnValue( + NODE_CREATOR_OPEN_SOURCES.ADD_NODE_BUTTON, + ); + vi.spyOn(nodeCreatorStore, 'selectedView', 'get').mockReturnValue(TRIGGER_NODE_CREATOR_VIEW); + nodeTypesStore.nodeTypes = { + [SCHEDULE_TRIGGER_NODE_TYPE]: { + 1: { + name: SCHEDULE_TRIGGER_NODE_TYPE, + displayName: 'Schedule Trigger', + group: ['trigger'], + version: 1, + defaults: {}, + inputs: [], + outputs: [], + properties: [], + description: '', + }, + }, + }; + const { getAddedNodesAndConnections } = useActions(); + + expect( + getAddedNodesAndConnections([ + { type: SCHEDULE_TRIGGER_NODE_TYPE, openDetail: true }, + { type: SLACK_NODE_TYPE }, + ]), + ).toEqual({ + connections: [{ from: { nodeIndex: 0 }, to: { nodeIndex: 1 } }], + nodes: [{ type: SCHEDULE_TRIGGER_NODE_TYPE, openDetail: true }, { type: SLACK_NODE_TYPE }], + }); + }); + + test('should connect node to webhook trigger when adding them together', () => { + const workflowsStore = useWorkflowsStore(); + const nodeCreatorStore = useNodeCreatorStore(); + const nodeTypesStore = useNodeTypesStore(); + + vi.spyOn(workflowsStore, 'workflowTriggerNodes', 'get').mockReturnValue([ + { type: SCHEDULE_TRIGGER_NODE_TYPE } as never, + ]); + vi.spyOn(nodeCreatorStore, 'openSource', 'get').mockReturnValue( + NODE_CREATOR_OPEN_SOURCES.ADD_NODE_BUTTON, + ); + vi.spyOn(nodeCreatorStore, 'selectedView', 'get').mockReturnValue(TRIGGER_NODE_CREATOR_VIEW); + nodeTypesStore.nodeTypes = { + [WEBHOOK_NODE_TYPE]: { + 1: { + name: WEBHOOK_NODE_TYPE, + displayName: 'Webhook', + group: ['trigger'], + version: 1, + defaults: {}, + inputs: [], + outputs: [], + properties: [], + description: '', + }, + }, + }; + const { getAddedNodesAndConnections } = useActions(); + + expect( + getAddedNodesAndConnections([ + { type: WEBHOOK_NODE_TYPE, openDetail: true }, + { type: SLACK_NODE_TYPE }, + ]), + ).toEqual({ + connections: [{ from: { nodeIndex: 0 }, to: { nodeIndex: 1 } }], + nodes: [{ type: WEBHOOK_NODE_TYPE, openDetail: true }, { type: SLACK_NODE_TYPE }], + }); + }); }); }); diff --git a/packages/editor-ui/src/components/Node/NodeCreator/composables/useActions.ts b/packages/editor-ui/src/components/Node/NodeCreator/composables/useActions.ts index 0e1b154627..3a49ff03e1 100644 --- a/packages/editor-ui/src/components/Node/NodeCreator/composables/useActions.ts +++ b/packages/editor-ui/src/components/Node/NodeCreator/composables/useActions.ts @@ -163,6 +163,18 @@ export const useActions = () => { }; } + /** + * Checks if added nodes contain trigger followed by another node + * In this case, we should connect the trigger with the following node + */ + function shouldConnectWithExistingTrigger(addedNodes: AddedNode[]): boolean { + if (addedNodes.length === 2) { + const isTriggerNode = useNodeTypesStore().isTriggerNode(addedNodes[0].type); + return isTriggerNode; + } + return false; + } + function shouldPrependManualTrigger(addedNodes: AddedNode[]): boolean { const { selectedView, openSource } = useNodeCreatorStore(); const { workflowTriggerNodes } = useWorkflowsStore(); @@ -228,6 +240,11 @@ export const useActions = () => { from: { nodeIndex: 0 }, to: { nodeIndex: 1 }, }); + } else if (shouldConnectWithExistingTrigger(addedNodes)) { + connections.push({ + from: { nodeIndex: 0 }, + to: { nodeIndex: 1 }, + }); } addedNodes.forEach((node, index) => {