-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Fix workflow initilisation for test definition routes & …
…add unit tests (#12507)
- Loading branch information
1 parent
c28f302
commit 2775f61
Showing
11 changed files
with
302 additions
and
83 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
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
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
143 changes: 143 additions & 0 deletions
143
packages/editor-ui/src/components/TestDefinition/EditDefinition/tests/NodesPinning.test.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,143 @@ | ||
import { waitFor } from '@testing-library/vue'; | ||
import { createPinia, setActivePinia } from 'pinia'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import NodesPinning from '../NodesPinning.vue'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { useWorkflowsStore } from '@/stores/workflows.store'; | ||
import { useNodeTypesStore } from '@/stores/nodeTypes.store'; | ||
|
||
import { | ||
createTestNode, | ||
createTestWorkflow, | ||
createTestWorkflowObject, | ||
mockNodeTypeDescription, | ||
} from '@/__tests__/mocks'; | ||
import { mockedStore } from '@/__tests__/utils'; | ||
import { NodeConnectionType } from 'n8n-workflow'; | ||
import { SET_NODE_TYPE } from '@/constants'; | ||
|
||
vi.mock('vue-router', () => { | ||
const push = vi.fn(); | ||
return { | ||
useRouter: () => ({ | ||
push, | ||
}), | ||
useRoute: () => ({ | ||
params: { | ||
name: 'test-workflow', | ||
testId: 'test-123', | ||
}, | ||
}), | ||
RouterLink: { | ||
template: '<a><slot /></a>', | ||
}, | ||
}; | ||
}); | ||
|
||
const renderComponent = createComponentRenderer(NodesPinning, { | ||
props: { | ||
modelValue: [{ id: '1', name: 'Node 1' }], | ||
}, | ||
global: { | ||
plugins: [createTestingPinia()], | ||
}, | ||
}); | ||
|
||
describe('NodesPinning', () => { | ||
const workflowsStore = mockedStore(useWorkflowsStore); | ||
const nodes = [ | ||
createTestNode({ id: '1', name: 'Node 1', type: SET_NODE_TYPE }), | ||
createTestNode({ id: '2', name: 'Node 2', type: SET_NODE_TYPE }), | ||
]; | ||
|
||
const nodeTypesStore = mockedStore(useNodeTypesStore); | ||
const nodeTypeDescription = mockNodeTypeDescription({ | ||
name: SET_NODE_TYPE, | ||
inputs: [NodeConnectionType.Main], | ||
outputs: [NodeConnectionType.Main], | ||
}); | ||
nodeTypesStore.nodeTypes = { | ||
node: { 1: nodeTypeDescription }, | ||
}; | ||
|
||
nodeTypesStore.getNodeType = vi.fn().mockReturnValue(nodeTypeDescription); | ||
const workflow = createTestWorkflow({ | ||
id: 'test-workflow', | ||
name: 'Test Workflow', | ||
nodes, | ||
connections: {}, | ||
}); | ||
|
||
const workflowObject = createTestWorkflowObject(workflow); | ||
|
||
workflowsStore.getWorkflowById = vi.fn().mockReturnValue(workflow); | ||
workflowsStore.getCurrentWorkflow = vi.fn().mockReturnValue(workflowObject); | ||
beforeEach(() => { | ||
const pinia = createPinia(); | ||
setActivePinia(pinia); | ||
|
||
nodeTypesStore.setNodeTypes([nodeTypeDescription]); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render workflow nodes', async () => { | ||
const { container } = renderComponent(); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelectorAll('.vue-flow__node')).toHaveLength(2); | ||
}); | ||
|
||
expect(container.querySelector('[data-node-name="Node 1"]')).toBeInTheDocument(); | ||
expect(container.querySelector('[data-node-name="Node 2"]')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should update node classes when pinning/unpinning nodes', async () => { | ||
const { container } = renderComponent(); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelector('[data-node-name="Node 1"]')).toBeInTheDocument(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelector('[data-node-name="Node 1"]')).toHaveClass( | ||
'canvasNode pinnedNode', | ||
); | ||
expect(container.querySelector('[data-node-name="Node 2"]')).toHaveClass( | ||
'canvasNode notPinnedNode', | ||
); | ||
}); | ||
}); | ||
|
||
it('should emit update:modelValue when pinning nodes', async () => { | ||
const { container, emitted, getAllByTestId } = renderComponent(); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelector('[data-node-name="Node 1"]')).toBeInTheDocument(); | ||
}); | ||
const pinButton = getAllByTestId('node-pin-button')[1]; | ||
pinButton?.click(); | ||
|
||
expect(emitted('update:modelValue')).toBeTruthy(); | ||
expect(emitted('update:modelValue')[0]).toEqual([ | ||
[ | ||
{ id: '1', name: 'Node 1' }, | ||
{ id: '2', name: 'Node 2' }, | ||
], | ||
]); | ||
}); | ||
it('should emit update:modelValue when unpinning nodes', async () => { | ||
const { container, emitted, getAllByTestId } = renderComponent(); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelector('[data-node-name="Node 1"]')).toBeInTheDocument(); | ||
}); | ||
const pinButton = getAllByTestId('node-pin-button')[0]; | ||
pinButton?.click(); | ||
|
||
expect(emitted('update:modelValue')).toBeTruthy(); | ||
expect(emitted('update:modelValue')[0]).toEqual([[]]); | ||
}); | ||
}); |
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
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
Oops, something went wrong.