mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
fix( Switch Node): Disable expressions for Number of Outputs in v3.3 (#19075)
Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user