diff --git a/packages/editor-ui/src/composables/useRunWorkflow.ts b/packages/editor-ui/src/composables/useRunWorkflow.ts index 184359cde6..dffe7bebba 100644 --- a/packages/editor-ui/src/composables/useRunWorkflow.ts +++ b/packages/editor-ui/src/composables/useRunWorkflow.ts @@ -351,6 +351,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType { - const actual = await vi.importActual('./executionUtils'); - return { - ...actual, - openFormPopupWindow: vi.fn(), - }; -}); +const windowOpenSpy = vi.spyOn(window, 'open'); vi.mock('@/stores/root.store', () => ({ useRootStore: () => ({ @@ -81,12 +71,13 @@ describe('displayForm', () => { runData, pinData, destinationNode: undefined, + triggerNode: undefined, directParentNodes: [], source: undefined, getTestUrl: getTestUrlMock, }); - expect(openFormPopupWindow).not.toHaveBeenCalled(); + expect(windowOpenSpy).not.toHaveBeenCalled(); }); it('should skip nodes if destinationNode does not match and node is not a directParentNode', () => { @@ -114,12 +105,13 @@ describe('displayForm', () => { runData: undefined, pinData: {}, destinationNode: 'Node3', + triggerNode: undefined, directParentNodes: ['Node4'], source: undefined, getTestUrl: getTestUrlMock, }); - expect(openFormPopupWindow).not.toHaveBeenCalled(); + expect(windowOpenSpy).not.toHaveBeenCalled(); }); it('should not open pop-up if source is "RunData.ManualChatMessage"', () => { @@ -141,20 +133,62 @@ describe('displayForm', () => { runData: undefined, pinData: {}, destinationNode: undefined, + triggerNode: undefined, directParentNodes: [], source: 'RunData.ManualChatMessage', getTestUrl: getTestUrlMock, }); - expect(openFormPopupWindow).not.toHaveBeenCalled(); + expect(windowOpenSpy).not.toHaveBeenCalled(); }); - describe('executionFilterToQueryFilter()', () => { - it('adds "new" to the filter', () => { - expect(executionFilterToQueryFilter({ status: 'new' }).status).toStrictEqual( - expect.arrayContaining(['new']), - ); + describe('with trigger node', () => { + const nodes: INode[] = [ + createTestNode({ name: 'Node1', type: FORM_TRIGGER_NODE_TYPE }), + createTestNode({ name: 'Node2', type: CHAT_TRIGGER_NODE_TYPE }), + ]; + + beforeEach(() => { + getTestUrlMock.mockReturnValue('http://test-url.com'); }); + + it('should open pop-up if the trigger node is a form node', () => { + displayForm({ + nodes, + runData: undefined, + pinData: {}, + destinationNode: undefined, + triggerNode: 'Node1', + directParentNodes: [], + source: undefined, + getTestUrl: getTestUrlMock, + }); + + expect(windowOpenSpy).toHaveBeenCalled(); + }); + + it("should not open pop-up if the trigger node is specified and it isn't a form node", () => { + displayForm({ + nodes, + runData: undefined, + pinData: {}, + destinationNode: undefined, + triggerNode: 'Node2', + directParentNodes: [], + source: undefined, + getTestUrl: getTestUrlMock, + }); + + expect(windowOpenSpy).not.toHaveBeenCalled(); + }); + }); +}); + +describe('executionFilterToQueryFilter()', () => { + it('adds "new" to the filter', () => { + expect(executionFilterToQueryFilter({ status: 'new' }).status).toStrictEqual( + expect.arrayContaining(['new']), + ); }); }); diff --git a/packages/editor-ui/src/utils/executionUtils.ts b/packages/editor-ui/src/utils/executionUtils.ts index adcbbcd2ad..9421640bd4 100644 --- a/packages/editor-ui/src/utils/executionUtils.ts +++ b/packages/editor-ui/src/utils/executionUtils.ts @@ -105,6 +105,7 @@ export function displayForm({ runData, pinData, destinationNode, + triggerNode, directParentNodes, source, getTestUrl, @@ -113,11 +114,14 @@ export function displayForm({ runData: IRunData | undefined; pinData: IPinData; destinationNode: string | undefined; + triggerNode: string | undefined; directParentNodes: string[]; source: string | undefined; getTestUrl: (node: INode) => string; }) { for (const node of nodes) { + if (triggerNode !== undefined && triggerNode !== node.name) continue; + const hasNodeRun = runData && runData?.hasOwnProperty(node.name); if (hasNodeRun || pinData[node.name]) continue;