diff --git a/packages/frontend/editor-ui/src/components/VirtualSchema.test.ts b/packages/frontend/editor-ui/src/components/VirtualSchema.test.ts index 23172ccc451..8177f9d4ed1 100644 --- a/packages/frontend/editor-ui/src/components/VirtualSchema.test.ts +++ b/packages/frontend/editor-ui/src/components/VirtualSchema.test.ts @@ -744,6 +744,52 @@ describe('VirtualSchema.vue', () => { expect(container).toMatchSnapshot(); }); + it('does not filter single-output connected nodes by outputIndex', async () => { + // This test verifies the fix for the issue where nodes with single output connections + // were incorrectly being filtered by the current node's outputIndex + const originalNodeHelpers = nodeHelpers.useNodeHelpers(); + vi.spyOn(nodeHelpers, 'useNodeHelpers').mockImplementation(() => { + return { + ...originalNodeHelpers, + getLastRunIndexWithData: vi.fn(() => 0), + hasNodeExecuted: vi.fn(() => true), + getNodeInputData: vi.fn((node, _, outputIndex) => { + // Switch node has data on output 0 + if (node.name === 'If' && outputIndex === 0) { + return [{ json: { id: 1, name: 'John' } }, { json: { id: 2, name: 'Jane' } }]; + } + // No data on output 1 + if (node.name === 'If' && outputIndex === 1) { + return []; + } + return []; + }), + }; + }); + + const { getAllByTestId } = renderComponent({ + props: { + // If node is connected only via output 0 to the current node + nodes: [{ name: 'If', indicies: [0], depth: 2 }], + // Even though outputIndex is 1, the If node should still show its data + // because it only has a single connection (output 0) + outputIndex: 1, + }, + }); + + await waitFor(() => { + const headers = getAllByTestId('run-data-schema-header'); + expect(headers[0]).toHaveTextContent('If'); + // Should show 2 items from output 0, not filtered by outputIndex: 1 + expect(headers[0]).toHaveTextContent('2 items'); + + const items = getAllByTestId('run-data-schema-item'); + // Should show the data from output 0 + expect(items[0]).toHaveTextContent('id1'); + expect(items[1]).toHaveTextContent('nameJohn'); + }); + }); + it('renders schema for loop node done-branch with correct filtering', async () => { // Mock customer datastore output - 6 customer items const customerData = Array.from({ length: 6 }, (_, i) => ({ diff --git a/packages/frontend/editor-ui/src/components/VirtualSchema.vue b/packages/frontend/editor-ui/src/components/VirtualSchema.vue index 5e0ce41d7a0..85ce93788a6 100644 --- a/packages/frontend/editor-ui/src/components/VirtualSchema.vue +++ b/packages/frontend/editor-ui/src/components/VirtualSchema.vue @@ -117,11 +117,24 @@ const getNodeSchema = async (fullNode: INodeUi, connectedNode: IConnectedNode) = })) .filter(({ runIndex }) => runIndex !== -1); - // If outputIndex is specified, only use data from that specific output branch - const filteredOutputsWithData = - props.outputIndex !== undefined - ? connectedOutputsWithData.filter(({ outputIndex }) => outputIndex === props.outputIndex) - : connectedOutputsWithData; + // For connected nodes with multiple outputs that connect to the current node, + // filter by outputIndex if it's specified and matches one of the connected outputs + // This ensures we show the correct branch when viewing multi-output nodes like SplitInBatches + let filteredOutputsWithData = connectedOutputsWithData; + + // Only apply outputIndex filtering if: + // 1. outputIndex is specified + // 2. The node has multiple connected outputs + // 3. The specified outputIndex is one of the connected outputs + if ( + props.outputIndex !== undefined && + connectedOutputIndexes.length > 1 && + connectedOutputIndexes.includes(props.outputIndex) + ) { + filteredOutputsWithData = connectedOutputsWithData.filter( + ({ outputIndex }) => outputIndex === props.outputIndex, + ); + } const nodeData = filteredOutputsWithData .map(({ outputIndex, runIndex }) =>