diff --git a/frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.test.tsx b/frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.test.tsx index e0ad6b87a7b..433fc2a6194 100644 --- a/frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.test.tsx +++ b/frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.test.tsx @@ -137,4 +137,68 @@ describe('EditStringValue', () => { ); }); }); + + it('should initially set value as NO_VALUE if no value is selected', () => { + const handleComponentChange = jest.fn(); + renderEditStringValue({ handleComponentChange, enumValues: ['one', 'two', 'three'] }); + + const selectElement = screen.getByRole('combobox', { + name: textMock('ux_editor.component_properties.maxLength'), + }); + + expect(selectElement).toHaveValue('NO_VALUE'); + }); + + it('should set value when initially undefined and an option is clicked', async () => { + const handleComponentChange = jest.fn(); + renderEditStringValue({ handleComponentChange, enumValues: ['one', 'two', 'three'] }); + + const selectElement = screen.getByRole('combobox', { + name: textMock('ux_editor.component_properties.maxLength'), + }); + + await user.selectOptions(selectElement, 'one'); + + expect(handleComponentChange).toHaveBeenCalledWith({ + id: 'c24d0812-0c34-4582-8f31-ff4ce9795e96', + type: ComponentType.Input, + maxLength: 'one', + textResourceBindings: { + title: 'ServiceName', + }, + itemType: 'COMPONENT', + dataModelBindings: { simpleBinding: 'some-path' }, + }); + }); + + it('should set value to undefined when it had a value and the "no value" option is selected', async () => { + const handleComponentChange = jest.fn(); + renderEditStringValue({ + handleComponentChange, + enumValues: ['one', 'two', 'three'], + maxLength: 'one', + }); + + const selectElement = screen.getByRole('combobox', { + name: textMock('ux_editor.component_properties.maxLength'), + }); + + expect(selectElement).toHaveValue('one'); + + await user.selectOptions( + selectElement, + textMock('ux_editor.edit_component.no_value_selected_for_select'), + ); + + expect(handleComponentChange).toHaveBeenCalledWith({ + id: 'c24d0812-0c34-4582-8f31-ff4ce9795e96', + type: ComponentType.Input, + maxLength: undefined, + textResourceBindings: { + title: 'ServiceName', + }, + itemType: 'COMPONENT', + dataModelBindings: { simpleBinding: 'some-path' }, + }); + }); });