From 43aff2f856d93d05164cbd343a494eb9daff7930 Mon Sep 17 00:00:00 2001 From: Jethary Date: Tue, 2 Apr 2024 14:13:07 -0400 Subject: [PATCH] fix when snackbar is rendered! --- .../ProtocolSetupParameters/ChooseEnum.tsx | 10 ++++++---- .../__tests__/ChooseEnum.test.tsx | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/organisms/ProtocolSetupParameters/ChooseEnum.tsx b/app/src/organisms/ProtocolSetupParameters/ChooseEnum.tsx index e2f97e5e894..60e1d7a1b03 100644 --- a/app/src/organisms/ProtocolSetupParameters/ChooseEnum.tsx +++ b/app/src/organisms/ProtocolSetupParameters/ChooseEnum.tsx @@ -38,6 +38,7 @@ export function ChooseEnum({ const handleOnClick = (newValue: string | number | boolean): void => { setParameter(newValue, parameter.variableName) } + const resetValueDisabled = parameter.default === rawValue return ( <> @@ -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) + } /> { 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')