mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(editor): Connecting nodes to triggers when adding them together (#9042)
This commit is contained in:
parent
32df17104c
commit
f2143620ba
|
@ -660,16 +660,19 @@ describe('NDV', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stop listening for trigger event from NDV', () => {
|
it('Stop listening for trigger event from NDV', () => {
|
||||||
|
cy.intercept('POST', '/rest/workflows/run').as('workflowRun');
|
||||||
workflowPage.actions.addInitialNodeToCanvas('Local File Trigger', {
|
workflowPage.actions.addInitialNodeToCanvas('Local File Trigger', {
|
||||||
keepNdvOpen: true,
|
keepNdvOpen: true,
|
||||||
action: 'On Changes To A Specific File',
|
action: 'On Changes To A Specific File',
|
||||||
isTrigger: true,
|
isTrigger: true,
|
||||||
});
|
});
|
||||||
ndv.getters.triggerPanelExecuteButton().should('exist');
|
ndv.getters.triggerPanelExecuteButton().should('exist');
|
||||||
ndv.getters.triggerPanelExecuteButton().click();
|
ndv.getters.triggerPanelExecuteButton().realClick();
|
||||||
ndv.getters.triggerPanelExecuteButton().should('contain', 'Stop Listening');
|
ndv.getters.triggerPanelExecuteButton().should('contain', 'Stop Listening');
|
||||||
ndv.getters.triggerPanelExecuteButton().click();
|
ndv.getters.triggerPanelExecuteButton().realClick();
|
||||||
ndv.getters.triggerPanelExecuteButton().should('contain', 'Test step');
|
cy.wait('@workflowRun').then(() => {
|
||||||
workflowPage.getters.successToast().should('exist');
|
ndv.getters.triggerPanelExecuteButton().should('contain', 'Test step');
|
||||||
|
workflowPage.getters.successToast().should('exist');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { setActivePinia } from 'pinia';
|
import { setActivePinia } from 'pinia';
|
||||||
import { createTestingPinia } from '@pinia/testing';
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
import { useNodeCreatorStore } from '@/stores/nodeCreator.store';
|
import { useNodeCreatorStore } from '@/stores/nodeCreator.store';
|
||||||
|
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||||
import { useActions } from '../composables/useActions';
|
import { useActions } from '../composables/useActions';
|
||||||
import {
|
import {
|
||||||
|
@ -9,8 +10,10 @@ import {
|
||||||
NODE_CREATOR_OPEN_SOURCES,
|
NODE_CREATOR_OPEN_SOURCES,
|
||||||
NO_OP_NODE_TYPE,
|
NO_OP_NODE_TYPE,
|
||||||
SCHEDULE_TRIGGER_NODE_TYPE,
|
SCHEDULE_TRIGGER_NODE_TYPE,
|
||||||
|
SLACK_NODE_TYPE,
|
||||||
SPLIT_IN_BATCHES_NODE_TYPE,
|
SPLIT_IN_BATCHES_NODE_TYPE,
|
||||||
TRIGGER_NODE_CREATOR_VIEW,
|
TRIGGER_NODE_CREATOR_VIEW,
|
||||||
|
WEBHOOK_NODE_TYPE,
|
||||||
} from '@/constants';
|
} from '@/constants';
|
||||||
|
|
||||||
describe('useActions', () => {
|
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 }],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 {
|
function shouldPrependManualTrigger(addedNodes: AddedNode[]): boolean {
|
||||||
const { selectedView, openSource } = useNodeCreatorStore();
|
const { selectedView, openSource } = useNodeCreatorStore();
|
||||||
const { workflowTriggerNodes } = useWorkflowsStore();
|
const { workflowTriggerNodes } = useWorkflowsStore();
|
||||||
|
@ -228,6 +240,11 @@ export const useActions = () => {
|
||||||
from: { nodeIndex: 0 },
|
from: { nodeIndex: 0 },
|
||||||
to: { nodeIndex: 1 },
|
to: { nodeIndex: 1 },
|
||||||
});
|
});
|
||||||
|
} else if (shouldConnectWithExistingTrigger(addedNodes)) {
|
||||||
|
connections.push({
|
||||||
|
from: { nodeIndex: 0 },
|
||||||
|
to: { nodeIndex: 1 },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addedNodes.forEach((node, index) => {
|
addedNodes.forEach((node, index) => {
|
||||||
|
|
Loading…
Reference in a new issue