Skip to content

Commit

Permalink
fix when snackbar is rendered!
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Apr 2, 2024
1 parent 2655457 commit 43aff2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/organisms/ProtocolSetupParameters/ChooseEnum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function ChooseEnum({
const handleOnClick = (newValue: string | number | boolean): void => {
setParameter(newValue, parameter.variableName)
}
const resetValueDisabled = parameter.default === rawValue

return (
<>
Expand All @@ -46,10 +47,11 @@ export function ChooseEnum({
onClickBack={handleGoBack}
buttonType="tertiaryLowLight"
buttonText={t('restore_default')}
onClickButton={() => {
setParameter(parameter.default, parameter.variableName)
makeSnackbar(t('no_custom_values'))
}}
onClickButton={() =>
resetValueDisabled
? makeSnackbar(t('no_custom_values'))
: setParameter(parameter.default, parameter.variableName)
}
/>
<Flex
marginTop="7.75rem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ describe('ChooseEnum', () => {
fireEvent.click(screen.getAllByRole('button')[0])
expect(props.handleGoBack).toHaveBeenCalled()
})
it('calls the prop if reset default is clicked when the default has changed', () => {
render(props)
fireEvent.click(screen.getByText('Restore default values'))
expect(props.setParameter).toHaveBeenCalled()
})
it('calls does not call prop if reset default is clicked when the default has not changed', () => {
props = {
...props,
rawValue: 'none',
}
render(props)
fireEvent.click(screen.getByText('Restore default values'))
expect(props.setParameter).not.toHaveBeenCalled()
})
it('should render the text and buttons for choice param', () => {
render(props)
screen.getByText('no offsets')
Expand Down

0 comments on commit 43aff2f

Please sign in to comment.