fix(editor): Don't open form popup window if different trigger node is used (#13391)

This commit is contained in:
autologie 2025-02-21 15:35:11 +01:00 committed by GitHub
parent 415e25b5d5
commit 57a9a5b15f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 22 deletions

View file

@ -351,6 +351,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
nodes: workflowData.nodes,
runData: workflowsStore.getWorkflowExecution?.data?.resultData?.runData,
destinationNode: options.destinationNode,
triggerNode: options.triggerNode,
pinData,
directParentNodes,
source: options.source,

View file

@ -1,23 +1,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import {
displayForm,
openFormPopupWindow,
executionFilterToQueryFilter,
waitingNodeTooltip,
} from './executionUtils';
import { displayForm, executionFilterToQueryFilter, waitingNodeTooltip } from './executionUtils';
import type { INode, IRunData, IPinData } from 'n8n-workflow';
import { type INodeUi } from '../Interface';
import { CHAT_TRIGGER_NODE_TYPE, FORM_TRIGGER_NODE_TYPE } from '@/constants';
import { createTestNode } from '@/__tests__/mocks';
const FORM_TRIGGER_NODE_TYPE = 'formTrigger';
const WAIT_NODE_TYPE = 'waitNode';
vi.mock('./executionUtils', async () => {
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']),
);
});
});

View file

@ -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;