-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [M3-6472] - [Marketplace] One Click Cluster - UDF Caching issue (#…
…8997) * fix: [M3-6472] - [Marketplace] One Click Cluster - UDF Caching issue * PR feedback * Update packages/manager/src/features/StackScripts/UserDefinedFieldsPanel/FieldTypes/UserDefinedSelect.tsx Co-authored-by: Banks Nussman <115251059+bnussman-akamai@users.noreply.github.com> * PR feedback * Update CHANGELOG.md --------- Co-authored-by: Banks Nussman <115251059+bnussman-akamai@users.noreply.github.com>
- Loading branch information
1 parent
ee30268
commit 2e0805a
Showing
4 changed files
with
160 additions
and
93 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
...er/src/features/StackScripts/UserDefinedFieldsPanel/FieldTypes/UserDefinedSelect.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,71 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
import { UserDefinedSelect } from './UserDefinedSelect'; | ||
|
||
describe('UserDefinedSelect', () => { | ||
it('renders select when oneof has more than 4 options', () => { | ||
const field = { | ||
name: 'selectField', | ||
label: 'Select Field', | ||
oneof: 'option1,option2,option3,option4,option5', | ||
}; | ||
const { getByLabelText, getByText } = renderWithTheme( | ||
<UserDefinedSelect | ||
field={field} | ||
value="" | ||
updateFormState={() => {}} | ||
isOptional={false} | ||
/> | ||
); | ||
|
||
const selectField = getByLabelText('Select Field'); | ||
fireEvent.change(selectField, { target: { value: 'option3' } }); | ||
|
||
expect(getByText('option3')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders radio when oneof has 4 or fewer options', () => { | ||
const field = { | ||
name: 'radioField', | ||
label: 'Radio Field', | ||
oneof: 'option1,option2,option3,option4', | ||
}; | ||
const updateFormState = jest.fn(); | ||
const { getAllByRole } = renderWithTheme( | ||
<UserDefinedSelect | ||
field={field} | ||
value="" | ||
updateFormState={updateFormState} | ||
isOptional={false} | ||
/> | ||
); | ||
|
||
const radioElements = getAllByRole('radio'); | ||
|
||
expect(radioElements.length).toEqual(4); | ||
}); | ||
|
||
it('calls updateFormState when a new option is selected', () => { | ||
const field = { | ||
name: 'selectField', | ||
label: 'Select Field', | ||
oneof: 'option1,option2,option3,option4', | ||
}; | ||
const updateFormState = jest.fn(); | ||
const { getAllByRole } = renderWithTheme( | ||
<UserDefinedSelect | ||
field={field} | ||
value="" | ||
updateFormState={updateFormState} | ||
isOptional={false} | ||
/> | ||
); | ||
|
||
const radioElements = getAllByRole('radio'); | ||
|
||
fireEvent.click(radioElements[2]); | ||
|
||
expect(updateFormState).toHaveBeenCalledWith('selectField', 'option3'); | ||
}); | ||
}); |
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
Oops, something went wrong.