Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wrt95 committed Oct 16, 2024
1 parent 7e6001b commit 0fde933
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
});
});

0 comments on commit 0fde933

Please sign in to comment.