From f1cbb7002f39dbfe8ef6000906e303e56f6fb7bb Mon Sep 17 00:00:00 2001 From: Federico Meini Date: Tue, 5 Nov 2024 13:58:45 +0100 Subject: [PATCH] Attempt testing the change --- packages/editor-ui/src/__tests__/render.ts | 20 +++++++ .../src/components/InputPanel.test.ts | 52 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 packages/editor-ui/src/components/InputPanel.test.ts diff --git a/packages/editor-ui/src/__tests__/render.ts b/packages/editor-ui/src/__tests__/render.ts index e46b615993..2a3f0798bd 100644 --- a/packages/editor-ui/src/__tests__/render.ts +++ b/packages/editor-ui/src/__tests__/render.ts @@ -1,5 +1,6 @@ import type { Plugin } from 'vue'; import { render } from '@testing-library/vue'; +import { mount } from '@vue/test-utils'; import { i18nInstance, I18nPlugin } from '@/plugins/i18n'; import { GlobalComponentsPlugin } from '@/plugins/components'; import { GlobalDirectivesPlugin } from '@/plugins/directives'; @@ -62,6 +63,25 @@ export function renderComponent(component: RenderComponent, options: RenderOptio }); } +export function mountComponent(component: RenderComponent, options: RenderOptions = {}) { + const { pinia, ...renderOptions } = options; + + return mount(component, { + ...defaultOptions, + ...renderOptions, + global: { + ...defaultOptions.global, + ...renderOptions.global, + stubs: { ...defaultOptions.global.stubs, ...(renderOptions.global?.stubs ?? {}) }, + plugins: [ + ...defaultOptions.global.plugins, + ...(renderOptions.global?.plugins ?? []), + ...(pinia ? [pinia] : []), + ], + }, + }); +} + export function createComponentRenderer( component: RenderComponent, defaultOptions: RenderOptions = {}, diff --git a/packages/editor-ui/src/components/InputPanel.test.ts b/packages/editor-ui/src/components/InputPanel.test.ts new file mode 100644 index 0000000000..36de5c52a5 --- /dev/null +++ b/packages/editor-ui/src/components/InputPanel.test.ts @@ -0,0 +1,52 @@ +import { createPinia, 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'; + +describe('InputPanel.vue', () => { + let pinia: ReturnType; + + beforeEach(() => { + pinia = createPinia(); + setActivePinia(pinia); + }); + + it('should compute rootNodesParents correctly', () => { + const nodes = [ + createTestNode({ name: 'Normal Node' }), + createTestNode({ name: 'Agent' }), + createTestNode({ name: 'Tool' }), + ]; + const connections: IConnections = { + [nodes[0].name]: { + [NodeConnectionType.Main]: [ + [{ node: nodes[1].name, type: NodeConnectionType.Main, index: 0 }], + ], + }, + [nodes[2].name]: { + [NodeConnectionType.AiMemory]: [ + [{ node: nodes[1].name, type: NodeConnectionType.AiMemory, index: 0 }], + ], + }, + }; + const workflowObject = createTestWorkflowObject({ + nodes, + connections, + }); + + // Mount the component + const wrapper = mountComponent(InputPanel, { + pinia, + props: { + currentNodeName: 'Agent', + runIndex: 0, + workflow: workflowObject, + }, + }); + + // Assert the computed property returns the expected value + // TODO: Update the expected value + expect(wrapper.vm.rootNodesParents).toEqual(['Tool']); + }); +});