diff --git a/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.test.tsx b/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.test.tsx index ca38c227d..1467728d8 100644 --- a/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.test.tsx +++ b/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.test.tsx @@ -149,29 +149,60 @@ describe('MonthlyGoalAccordion', () => { }); }); - it('resets goal to calculated goal', async () => { - const { getByRole, findByText } = render( - , - ); - const input = getByRole('spinbutton', { name: label }); - - expect( - await findByText( - 'Based on the past year, NetSuite estimates that you need at least $1,500 of monthly support. You can use this amount or choose your own target monthly goal.', - ), - ).toBeInTheDocument(); - - const resetButton = getByRole('button', { name: /Reset/ }); - userEvent.click(resetButton); - expect(input).toHaveValue(1500); - expect(resetButton).not.toBeInTheDocument(); + describe('calculated goal', () => { + it('resets goal to calculated goal', async () => { + const { getByRole, findByText } = render( + , + ); + const input = getByRole('spinbutton', { name: label }); + + expect( + await findByText( + 'Based on the past year, NetSuite estimates that you need at least $1,500 of monthly support. You can use this amount or choose your own target monthly goal.', + ), + ).toBeInTheDocument(); + + const resetButton = getByRole('button', { name: /Reset/ }); + userEvent.click(resetButton); + expect(input).toHaveValue(1500); + expect(resetButton).not.toBeInTheDocument(); + + await waitFor(() => + expect(mutationSpy).toHaveGraphqlOperation('UpdateAccountPreferences', { + input: { + id: accountListId, + attributes: { + settings: { + monthlyGoal: 1500, + }, + }, + }, + }), + ); + }); - userEvent.clear(input); - userEvent.type(input, '500'); - expect(getByRole('button', { name: /Reset/ })).toBeInTheDocument(); + it('hides reset button if goal matches calculated goal', async () => { + const { getByRole, findByText, queryByRole } = render( + , + ); + + expect( + await findByText( + 'Based on the past year, NetSuite estimates that you need at least $1,000 of monthly support. You can use this amount or choose your own target monthly goal.', + ), + ).toBeInTheDocument(); + expect(queryByRole('button', { name: /Reset/ })).not.toBeInTheDocument(); + + userEvent.type(getByRole('spinbutton', { name: label }), '0'); + expect(getByRole('button', { name: /Reset/ })).toBeInTheDocument(); + }); }); }); diff --git a/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.tsx b/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.tsx index d0f5a9a43..64af8114c 100644 --- a/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.tsx +++ b/src/components/Settings/preferences/accordions/MonthlyGoalAccordion/MonthlyGoalAccordion.tsx @@ -135,6 +135,7 @@ export const MonthlyGoalAccordion: React.FC = ({ values: { monthlyGoal }, errors, handleSubmit, + submitForm, isSubmitting, isValid, handleChange, @@ -180,7 +181,10 @@ export const MonthlyGoalAccordion: React.FC = ({