diff --git a/packages/nodes-base/nodes/Switch/Switch.node.ts b/packages/nodes-base/nodes/Switch/Switch.node.ts index 1a85852a1c..6d6dba55ea 100644 --- a/packages/nodes-base/nodes/Switch/Switch.node.ts +++ b/packages/nodes-base/nodes/Switch/Switch.node.ts @@ -14,7 +14,7 @@ export class Switch extends VersionedNodeType { iconColor: 'light-blue', group: ['transform'], description: 'Route items depending on defined expression or rules', - defaultVersion: 3.2, + defaultVersion: 3.3, }; const nodeVersions: IVersionedNodeType['nodeVersions'] = { @@ -23,6 +23,7 @@ export class Switch extends VersionedNodeType { 3: new SwitchV3(baseDescription), 3.1: new SwitchV3(baseDescription), 3.2: new SwitchV3(baseDescription), + 3.3: new SwitchV3(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Switch/V3/SwitchV3.node.ts b/packages/nodes-base/nodes/Switch/V3/SwitchV3.node.ts index 2cda9e9e33..d182f738e9 100644 --- a/packages/nodes-base/nodes/Switch/V3/SwitchV3.node.ts +++ b/packages/nodes-base/nodes/Switch/V3/SwitchV3.node.ts @@ -52,7 +52,7 @@ export class SwitchV3 implements INodeType { this.description = { ...baseDescription, subtitle: `=mode: {{(${capitalize})($parameter["mode"])}}`, - version: [3, 3.1, 3.2], + version: [3, 3.1, 3.2, 3.3], defaults: { name: 'Switch', color: '#506000', @@ -84,9 +84,24 @@ export class SwitchV3 implements INodeType { displayName: 'Number of Outputs', name: 'numberOutputs', type: 'number', + noDataExpression: true, displayOptions: { show: { mode: ['expression'], + '@version': [{ _cnd: { gte: 3.3 } }], + }, + }, + default: 4, + description: 'How many outputs to create', + }, + { + displayName: 'Number of Outputs', + name: 'numberOutputs', + type: 'number', + displayOptions: { + show: { + mode: ['expression'], + '@version': [{ _cnd: { lt: 3.3 } }], }, }, default: 4, diff --git a/packages/nodes-base/nodes/Switch/V3/test/switch.node.test.ts b/packages/nodes-base/nodes/Switch/V3/test/switch.node.test.ts index c28bc0e906..bbac96233b 100644 --- a/packages/nodes-base/nodes/Switch/V3/test/switch.node.test.ts +++ b/packages/nodes-base/nodes/Switch/V3/test/switch.node.test.ts @@ -1,5 +1,57 @@ import { NodeTestHarness } from '@nodes-testing/node-test-harness'; +import type { INodeTypeBaseDescription } from 'n8n-workflow'; + +import { SwitchV3 } from '../SwitchV3.node'; describe('Execute Switch Node', () => { new NodeTestHarness().setupTests(); + + describe('Version-specific behavior', () => { + const baseDescription: INodeTypeBaseDescription = { + displayName: 'Switch', + name: 'n8n-nodes-base.switch', + group: ['transform'], + description: 'Route items to different outputs', + }; + + it('should have two numberOutputs parameters with different version conditions', () => { + const switchNode = new SwitchV3(baseDescription); + const numberOutputsParams = switchNode.description.properties.filter( + (prop) => prop.name === 'numberOutputs', + ); + + expect(numberOutputsParams).toHaveLength(2); + }); + + it('should have noDataExpression: true for version 3.3+ numberOutputs parameter', () => { + const switchNode = new SwitchV3(baseDescription); + const numberOutputsParamWithNoExpression = switchNode.description.properties.find( + (prop) => prop.name === 'numberOutputs' && prop.noDataExpression === true, + ); + + expect(numberOutputsParamWithNoExpression).toBeDefined(); + expect(numberOutputsParamWithNoExpression?.noDataExpression).toBe(true); + expect(numberOutputsParamWithNoExpression?.displayOptions?.show?.['@version']).toEqual([ + { _cnd: { gte: 3.3 } }, + ]); + }); + + it('should have numberOutputs parameter without noDataExpression for older versions', () => { + const switchNode = new SwitchV3(baseDescription); + const numberOutputsParamWithoutNoExpression = switchNode.description.properties.find( + (prop) => prop.name === 'numberOutputs' && !prop.noDataExpression, + ); + + expect(numberOutputsParamWithoutNoExpression).toBeDefined(); + expect(numberOutputsParamWithoutNoExpression?.noDataExpression).toBeUndefined(); + expect(numberOutputsParamWithoutNoExpression?.displayOptions?.show?.['@version']).toEqual([ + { _cnd: { lt: 3.3 } }, + ]); + }); + + it('should include version 3.3 in supported versions', () => { + const switchNode = new SwitchV3(baseDescription); + expect(switchNode.description.version).toContain(3.3); + }); + }); });