-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(n8n Form Trigger Node): Do not rerun trigger when it has run data (…
- Loading branch information
1 parent
37a8088
commit 3adbcab
Showing
3 changed files
with
230 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/editor-ui/src/utils/__tests__/executionUtils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { displayForm, openPopUpWindow } from '../executionUtils'; | ||
import type { INode, IRunData, IPinData } from 'n8n-workflow'; | ||
|
||
const FORM_TRIGGER_NODE_TYPE = 'formTrigger'; | ||
const WAIT_NODE_TYPE = 'waitNode'; | ||
|
||
vi.mock('../executionUtils', async () => { | ||
const actual = await vi.importActual('../executionUtils'); | ||
return { | ||
...actual, | ||
openPopUpWindow: vi.fn(), | ||
}; | ||
}); | ||
|
||
describe('displayForm', () => { | ||
const getTestUrlMock = vi.fn(); | ||
const shouldShowFormMock = vi.fn(); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should not call openPopUpWindow if node has already run or is pinned', () => { | ||
const nodes: INode[] = [ | ||
{ | ||
id: '1', | ||
name: 'Node1', | ||
typeVersion: 1, | ||
type: FORM_TRIGGER_NODE_TYPE, | ||
position: [0, 0], | ||
parameters: {}, | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Node2', | ||
typeVersion: 1, | ||
type: WAIT_NODE_TYPE, | ||
position: [0, 0], | ||
parameters: {}, | ||
}, | ||
]; | ||
|
||
const runData: IRunData = { Node1: [] }; | ||
const pinData: IPinData = { Node2: [{ json: { data: {} } }] }; | ||
|
||
displayForm({ | ||
nodes, | ||
runData, | ||
pinData, | ||
destinationNode: undefined, | ||
directParentNodes: [], | ||
formWaitingUrl: 'http://example.com', | ||
executionId: undefined, | ||
source: undefined, | ||
getTestUrl: getTestUrlMock, | ||
shouldShowForm: shouldShowFormMock, | ||
}); | ||
|
||
expect(openPopUpWindow).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should skip nodes if destinationNode does not match and node is not a directParentNode', () => { | ||
const nodes: INode[] = [ | ||
{ | ||
id: '1', | ||
name: 'Node1', | ||
typeVersion: 1, | ||
type: FORM_TRIGGER_NODE_TYPE, | ||
position: [0, 0], | ||
parameters: {}, | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Node2', | ||
typeVersion: 1, | ||
type: WAIT_NODE_TYPE, | ||
position: [0, 0], | ||
parameters: {}, | ||
}, | ||
]; | ||
|
||
displayForm({ | ||
nodes, | ||
runData: undefined, | ||
pinData: {}, | ||
destinationNode: 'Node3', | ||
directParentNodes: ['Node4'], | ||
formWaitingUrl: 'http://example.com', | ||
executionId: '12345', | ||
source: undefined, | ||
getTestUrl: getTestUrlMock, | ||
shouldShowForm: shouldShowFormMock, | ||
}); | ||
|
||
expect(openPopUpWindow).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not open pop-up if source is "RunData.ManualChatMessage"', () => { | ||
const nodes: INode[] = [ | ||
{ | ||
id: '1', | ||
name: 'Node1', | ||
typeVersion: 1, | ||
type: FORM_TRIGGER_NODE_TYPE, | ||
position: [0, 0], | ||
parameters: {}, | ||
}, | ||
]; | ||
|
||
getTestUrlMock.mockReturnValue('http://test-url.com'); | ||
|
||
displayForm({ | ||
nodes, | ||
runData: undefined, | ||
pinData: {}, | ||
destinationNode: undefined, | ||
directParentNodes: [], | ||
formWaitingUrl: 'http://example.com', | ||
executionId: undefined, | ||
source: 'RunData.ManualChatMessage', | ||
getTestUrl: getTestUrlMock, | ||
shouldShowForm: shouldShowFormMock, | ||
}); | ||
|
||
expect(openPopUpWindow).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters