Attempt testing the change

This commit is contained in:
Federico Meini 2024-11-05 13:58:45 +01:00
parent a8d81149b3
commit f1cbb7002f
No known key found for this signature in database
2 changed files with 72 additions and 0 deletions

View file

@ -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 = {},

View file

@ -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<typeof createPinia>;
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']);
});
});