mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Allow switch to Fixed
for boolean and number parameters with invalid expressions (#12948)
This commit is contained in:
parent
c60cc43124
commit
118be24d25
|
@ -8,6 +8,7 @@ import { waitFor } from '@testing-library/vue';
|
|||
import userEvent from '@testing-library/user-event';
|
||||
import type { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { cleanupAppModals, createAppModals } from '@/__tests__/utils';
|
||||
import { createEventBus } from 'n8n-design-system';
|
||||
|
||||
let mockNdvState: Partial<ReturnType<typeof useNDVStore>>;
|
||||
let mockNodeTypesState: Partial<ReturnType<typeof useNodeTypesStore>>;
|
||||
|
@ -233,4 +234,88 @@ describe('ParameterInput.vue', () => {
|
|||
|
||||
expect(emitted('update')).toBeUndefined();
|
||||
});
|
||||
|
||||
test('should reset bool on eventBus:removeExpression', async () => {
|
||||
const eventBus = createEventBus();
|
||||
const { emitted } = renderComponent(ParameterInput, {
|
||||
pinia: createTestingPinia(),
|
||||
props: {
|
||||
path: 'aSwitch',
|
||||
parameter: {
|
||||
displayName: 'A Switch',
|
||||
name: 'aSwitch',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
modelValue: '={{ }}', // note that this makes a syntax error
|
||||
eventBus,
|
||||
},
|
||||
});
|
||||
|
||||
eventBus.emit('optionSelected', 'removeExpression');
|
||||
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: true })]);
|
||||
});
|
||||
|
||||
test('should reset bool with undefined evaluation on eventBus:removeExpression', async () => {
|
||||
const eventBus = createEventBus();
|
||||
const { emitted } = renderComponent(ParameterInput, {
|
||||
pinia: createTestingPinia(),
|
||||
props: {
|
||||
path: 'aSwitch',
|
||||
parameter: {
|
||||
displayName: 'A Switch',
|
||||
name: 'aSwitch',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
modelValue: undefined,
|
||||
eventBus,
|
||||
},
|
||||
});
|
||||
|
||||
eventBus.emit('optionSelected', 'removeExpression');
|
||||
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: true })]);
|
||||
});
|
||||
|
||||
test('should reset number on eventBus:removeExpression', async () => {
|
||||
const eventBus = createEventBus();
|
||||
const { emitted } = renderComponent(ParameterInput, {
|
||||
pinia: createTestingPinia(),
|
||||
props: {
|
||||
path: 'aNum',
|
||||
parameter: {
|
||||
displayName: 'A Num',
|
||||
name: 'aNum',
|
||||
type: 'number',
|
||||
default: 6,
|
||||
},
|
||||
modelValue: '={{ }}', // note that this makes a syntax error
|
||||
eventBus,
|
||||
},
|
||||
});
|
||||
|
||||
eventBus.emit('optionSelected', 'removeExpression');
|
||||
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: 6 })]);
|
||||
});
|
||||
|
||||
test('should reset string on eventBus:removeExpression', async () => {
|
||||
const eventBus = createEventBus();
|
||||
const { emitted } = renderComponent(ParameterInput, {
|
||||
pinia: createTestingPinia(),
|
||||
props: {
|
||||
path: 'aStr',
|
||||
parameter: {
|
||||
displayName: 'A Str',
|
||||
name: 'aStr',
|
||||
type: 'string',
|
||||
default: 'some default',
|
||||
},
|
||||
modelValue: '={{ }}', // note that this makes a syntax error
|
||||
eventBus,
|
||||
},
|
||||
});
|
||||
|
||||
eventBus.emit('optionSelected', 'removeExpression');
|
||||
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: '{{ }}' })]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -908,11 +908,16 @@ async function optionSelected(command: string) {
|
|||
if (isResourceLocatorParameter.value && isResourceLocatorValue(props.modelValue)) {
|
||||
valueChanged({ __rl: true, value, mode: props.modelValue.mode });
|
||||
} else {
|
||||
let newValue = typeof value !== 'undefined' ? value : null;
|
||||
let newValue: NodeParameterValueType | {} = typeof value !== 'undefined' ? value : null;
|
||||
|
||||
if (props.parameter.type === 'string') {
|
||||
// Strip the '=' from the beginning
|
||||
newValue = modelValueString.value ? modelValueString.value.toString().substring(1) : null;
|
||||
} else if (newValue === null) {
|
||||
// Invalid expressions land here
|
||||
if (['number', 'boolean'].includes(props.parameter.type)) {
|
||||
newValue = props.parameter.default;
|
||||
}
|
||||
}
|
||||
valueChanged(newValue);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue