-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Simplify autocomplete input for V3 (#14262)
Co-authored-by: andreastanderen <[email protected]>
- Loading branch information
Showing
12 changed files
with
263 additions
and
261 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
frontend/libs/studio-components/src/components/StudioNativeSelect/StudioNativeSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/libs/studio-components/src/components/StudioNativeSelect/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { StudioNativeSelect } from './StudioNativeSelect'; | ||
export * from './StudioNativeSelect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 0 additions & 107 deletions
107
frontend/packages/ux-editor-v3/src/components/config/editModal/EditAutoComplete.test.tsx
This file was deleted.
Oops, something went wrong.
148 changes: 0 additions & 148 deletions
148
frontend/packages/ux-editor-v3/src/components/config/editModal/EditAutoComplete.tsx
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
...s/ux-editor-v3/src/components/config/editModal/EditAutocomplete/EditAutocomplete.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import type { EditAutocompleteProps } from './'; | ||
import { EditAutocomplete } from './'; | ||
import type { RenderResult } from '@testing-library/react'; | ||
import { screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { ComponentTypeV3 } from 'app-shared/types/ComponentTypeV3'; | ||
import type { FormComponent } from '../../../../types/FormComponent'; | ||
import { renderWithProviders } from '../../../../testing/mocks'; | ||
|
||
// Test data: | ||
const component: FormComponent<ComponentTypeV3.Input> = { | ||
id: 'random-id', | ||
autocomplete: '', | ||
type: ComponentTypeV3.Input, | ||
itemType: 'COMPONENT', | ||
propertyPath: 'definitions/inputComponent', | ||
dataModelBindings: {}, | ||
}; | ||
const handleComponentChange = jest.fn(); | ||
const defaultProps: EditAutocompleteProps = { | ||
handleComponentChange, | ||
component, | ||
}; | ||
|
||
describe('EditAutocomplete', () => { | ||
it('Calls handleComponentChange with the updated component when the value is changed ', async () => { | ||
const user = userEvent.setup(); | ||
const optionToChoose = 'on'; | ||
renderEditAutocomplete(); | ||
|
||
const combobox = screen.getByRole('combobox'); | ||
const option = screen.getByRole('option', { name: optionToChoose }); | ||
await user.selectOptions(combobox, option); | ||
|
||
expect(handleComponentChange).toHaveBeenCalledWith({ | ||
autocomplete: optionToChoose, | ||
dataModelBindings: {}, | ||
id: 'random-id', | ||
itemType: 'COMPONENT', | ||
propertyPath: 'definitions/inputComponent', | ||
type: 'Input', | ||
}); | ||
}); | ||
|
||
it('Renders with the given autocomplete value as selected', () => { | ||
const selectedValue = 'on'; | ||
const componentWithAutocomplete: FormComponent<ComponentTypeV3.Input> = { | ||
...component, | ||
autocomplete: selectedValue, | ||
}; | ||
renderEditAutocomplete({ component: componentWithAutocomplete }); | ||
expect(screen.getByRole('combobox')).toHaveValue(selectedValue); | ||
}); | ||
}); | ||
|
||
function renderEditAutocomplete(props: Partial<EditAutocompleteProps> = {}): RenderResult { | ||
return renderWithProviders(<EditAutocomplete {...defaultProps} {...props} />); | ||
} |
Oops, something went wrong.