mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Attempt testing the change
This commit is contained in:
parent
a8d81149b3
commit
f1cbb7002f
|
@ -1,5 +1,6 @@
|
||||||
import type { Plugin } from 'vue';
|
import type { Plugin } from 'vue';
|
||||||
import { render } from '@testing-library/vue';
|
import { render } from '@testing-library/vue';
|
||||||
|
import { mount } from '@vue/test-utils';
|
||||||
import { i18nInstance, I18nPlugin } from '@/plugins/i18n';
|
import { i18nInstance, I18nPlugin } from '@/plugins/i18n';
|
||||||
import { GlobalComponentsPlugin } from '@/plugins/components';
|
import { GlobalComponentsPlugin } from '@/plugins/components';
|
||||||
import { GlobalDirectivesPlugin } from '@/plugins/directives';
|
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(
|
export function createComponentRenderer(
|
||||||
component: RenderComponent,
|
component: RenderComponent,
|
||||||
defaultOptions: RenderOptions = {},
|
defaultOptions: RenderOptions = {},
|
||||||
|
|
52
packages/editor-ui/src/components/InputPanel.test.ts
Normal file
52
packages/editor-ui/src/components/InputPanel.test.ts
Normal 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']);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue