From fb662dd95cae3bc51d05d05e32e772d05adafa1e Mon Sep 17 00:00:00 2001 From: autologie Date: Thu, 23 Jan 2025 08:47:41 +0100 Subject: [PATCH] fix(editor): Show mappings by default in sub-node NDVs when the root node isn't executed (#12642) --- .../src/components/InputPanel.test.ts | 62 +++++++++++++++-- .../editor-ui/src/components/InputPanel.vue | 69 ++++++++++++++----- .../__snapshots__/InputPanel.test.ts.snap | 26 +++---- .../src/plugins/i18n/locales/en.json | 3 + 4 files changed, 124 insertions(+), 36 deletions(-) diff --git a/packages/editor-ui/src/components/InputPanel.test.ts b/packages/editor-ui/src/components/InputPanel.test.ts index 0b4734068a..a6c27abe8b 100644 --- a/packages/editor-ui/src/components/InputPanel.test.ts +++ b/packages/editor-ui/src/components/InputPanel.test.ts @@ -4,10 +4,15 @@ import InputPanel, { type Props } from '@/components/InputPanel.vue'; import { STORES } from '@/constants'; import { useWorkflowsStore } from '@/stores/workflows.store'; import { createTestingPinia } from '@pinia/testing'; -import { NodeConnectionType, type IConnections, type INodeExecutionData } from 'n8n-workflow'; +import { waitFor } from '@testing-library/vue'; +import { + NodeConnectionType, + type IConnections, + type INodeExecutionData, + type IRunData, +} from 'n8n-workflow'; import { setActivePinia } from 'pinia'; import { mockedStore } from '../__tests__/utils'; -import { waitFor } from '@testing-library/vue'; vi.mock('vue-router', () => { return { @@ -24,7 +29,7 @@ const nodes = [ createTestNode({ name: 'Tool' }), ]; -const render = (props: Partial = {}, pinData?: INodeExecutionData[]) => { +const render = (props: Partial = {}, pinData?: INodeExecutionData[], runData?: IRunData) => { const connections: IConnections = { [nodes[0].name]: { [NodeConnectionType.Main]: [ @@ -50,12 +55,38 @@ const render = (props: Partial = {}, pinData?: INodeExecutionData[]) => { setActivePinia(pinia); const workflow = createTestWorkflow({ nodes, connections }); - useWorkflowsStore().setWorkflow(workflow); + const workflowStore = useWorkflowsStore(); + + workflowStore.setWorkflow(workflow); if (pinData) { mockedStore(useWorkflowsStore).pinDataByNodeName.mockReturnValue(pinData); } + if (runData) { + workflowStore.setWorkflowExecutionData({ + id: '', + workflowData: { + id: '', + name: '', + active: false, + createdAt: '', + updatedAt: '', + nodes, + connections, + versionId: '', + }, + finished: false, + mode: 'trigger', + status: 'success', + startedAt: new Date(), + createdAt: new Date(), + data: { + resultData: { runData }, + }, + }); + } + const workflowObject = createTestWorkflowObject({ nodes, connections, @@ -83,4 +114,27 @@ describe('InputPanel', () => { await waitFor(() => expect(queryByTestId('ndv-data-size-warning')).not.toBeInTheDocument()); expect(container).toMatchSnapshot(); }); + + it("opens mapping tab by default if the node hasn't run yet", async () => { + const { findByTestId } = render({ currentNodeName: 'Tool' }); + + expect((await findByTestId('radio-button-mapping')).parentNode).toBeChecked(); + expect((await findByTestId('radio-button-debugging')).parentNode).not.toBeChecked(); + }); + + it('opens debugging tab by default if the node has already run', async () => { + const { findByTestId } = render({ currentNodeName: 'Tool' }, undefined, { + Tool: [ + { + startTime: 0, + executionTime: 0, + source: [], + data: {}, + }, + ], + }); + + expect((await findByTestId('radio-button-mapping')).parentNode).not.toBeChecked(); + expect((await findByTestId('radio-button-debugging')).parentNode).toBeChecked(); + }); }); diff --git a/packages/editor-ui/src/components/InputPanel.vue b/packages/editor-ui/src/components/InputPanel.vue index 2dab3ea97b..41b85e3389 100644 --- a/packages/editor-ui/src/components/InputPanel.vue +++ b/packages/editor-ui/src/components/InputPanel.vue @@ -1,27 +1,27 @@