mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
Use alternative store mocking strategy
This commit is contained in:
parent
391695862b
commit
8c5ada83a7
|
@ -1,17 +1,36 @@
|
|||
import { setActivePinia } from 'pinia';
|
||||
import InputPanel from '@/components/InputPanel.vue';
|
||||
import { mountComponent } from '@/__tests__/render';
|
||||
import { createTestNode, createTestWorkflowObject } from '@/__tests__/mocks';
|
||||
import { IConnections, NodeConnectionType } from 'n8n-workflow';
|
||||
import { createTestWorkflowObject, mockNode } from '@/__tests__/mocks';
|
||||
import type { IConnections } from 'n8n-workflow';
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { STORES } from '@/constants';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { mockedStore } from '@/__tests__/utils';
|
||||
import { AGENT_NODE_TYPE, CHAT_TRIGGER_NODE_TYPE, NO_OP_NODE_TYPE } from '@/constants';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { IWorkflowDb } from '@/Interface';
|
||||
|
||||
let mockNDVStore: ReturnType<typeof mockedStore<typeof useNDVStore>>;
|
||||
let mockWorkflowsStore: ReturnType<typeof mockedStore<typeof useWorkflowsStore>>;
|
||||
|
||||
describe('InputPanel.vue', () => {
|
||||
beforeEach(() => {
|
||||
createTestingPinia();
|
||||
|
||||
mockNDVStore = mockedStore(useNDVStore);
|
||||
mockWorkflowsStore = mockedStore(useWorkflowsStore);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should compute rootNodesParents correctly', () => {
|
||||
const nodes = [
|
||||
createTestNode({ name: 'Normal Node' }),
|
||||
createTestNode({ name: 'Agent' }),
|
||||
createTestNode({ name: 'Tool' }),
|
||||
mockNode({ name: 'Normal Node', type: CHAT_TRIGGER_NODE_TYPE }),
|
||||
mockNode({ name: 'Agent', type: AGENT_NODE_TYPE }),
|
||||
mockNode({ name: 'Tool', type: NO_OP_NODE_TYPE }),
|
||||
];
|
||||
const connections: IConnections = {
|
||||
[nodes[0].name]: {
|
||||
|
@ -25,28 +44,21 @@ describe('InputPanel.vue', () => {
|
|||
],
|
||||
},
|
||||
};
|
||||
|
||||
const workflowObject = createTestWorkflowObject({
|
||||
nodes,
|
||||
connections,
|
||||
});
|
||||
|
||||
const pinia = createTestingPinia({
|
||||
initialState: {
|
||||
[STORES.NDV]: {
|
||||
// TODO: this does not work, ned to fix
|
||||
activeNode: { name: 'Agent' },
|
||||
},
|
||||
[STORES.WORKFLOWS]: {
|
||||
workflow: workflowObject,
|
||||
},
|
||||
},
|
||||
mockNDVStore.activeNodeName = 'Agent';
|
||||
mockWorkflowsStore.workflow = mock<IWorkflowDb>({
|
||||
connections: connections,
|
||||
active: true,
|
||||
nodes: nodes,
|
||||
});
|
||||
|
||||
setActivePinia(pinia);
|
||||
|
||||
// Mount the component
|
||||
const wrapper = mountComponent(InputPanel, {
|
||||
pinia,
|
||||
props: {
|
||||
currentNodeName: 'Agent',
|
||||
runIndex: 0,
|
||||
|
|
Loading…
Reference in a new issue