From 1c779948f5fd3215b97e7981fdf730c585b0eed9 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:42:32 -0500 Subject: [PATCH 1/6] Add error handling to duplicate request mutation in CurrentBoardApproved component --- .../SharedComponents/CurrentBoardApproved.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx index a3e8f1a730..9ea077ad0f 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx @@ -68,6 +68,8 @@ export const CurrentBoardApproved: React.FC = ({ router.push(getRequestUrl(accountListId, newRequestId, 'edit')); } }, + // Prevents unhandled promise rejection + onError: () => {}, }); }; From 671a56b1f8ac09b6204988517cd1781c8b23e412 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:18:22 -0500 Subject: [PATCH 2/6] Refactor CurrentBoardApproved tests to decrease duplication, and include test for error handling --- .../CurrentBoardApproved.test.tsx | 160 +++++++++++------- 1 file changed, 98 insertions(+), 62 deletions(-) diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx index 83ba1791c4..5a57652000 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx @@ -1,11 +1,17 @@ import React from 'react'; +import { MockedProvider, MockedResponse } from '@apollo/client/testing'; import { ThemeProvider } from '@mui/material/styles'; import { render, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { GraphQLError } from 'graphql'; +import { DeepPartial } from 'ts-essentials'; import TestRouter from '__tests__/util/TestRouter'; import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; import theme from 'src/theme'; -import { DuplicateMinistryHousingAllowanceRequestMutation } from '../MinisterHousingAllowance.generated'; +import { + DuplicateMinistryHousingAllowanceRequestDocument, + DuplicateMinistryHousingAllowanceRequestMutation, +} from '../MinisterHousingAllowance.generated'; import { ContextType, HcmData, @@ -17,19 +23,40 @@ import { CurrentBoardApproved } from './CurrentBoardApproved'; const newRequestId = 'new-request-id'; const mutationSpy = jest.fn(); const mockPush = jest.fn(); + +const singleContext: Partial = { + isMarried: false, + preferredName: 'John', + spousePreferredName: '', + userHcmData: { + staffInfo: { + personNumber: '000123456', + }, + } as unknown as HcmData, + spouseHcmData: null, +}; + interface TestComponentProps { - contextValue: Partial; + contextValue?: Partial; + request?: typeof mockMHARequest; router?: { push?: jest.Mock; query?: { accountListId?: string }; }; + mocks?: DeepPartial<{ + DuplicateMinistryHousingAllowanceRequest: DuplicateMinistryHousingAllowanceRequestMutation; + }>; + errorMocks?: MockedResponse[]; } const TestComponent: React.FC = ({ - contextValue, + contextValue = singleContext, + request, router = {}, + mocks, + errorMocks, }) => { - const approvedMHARequest = { + const approvedMHARequest = request ?? { ...mockMHARequest, updatedAt: '2022-12-01', requestAttributes: { @@ -41,20 +68,29 @@ const TestComponent: React.FC = ({ }, }; + const content = ( + + + + ); + return ( - - onCall={mutationSpy} - > - {content} + ) : ( + + mocks={mocks} + onCall={mutationSpy} > - - - + {content} + + )} ); @@ -105,19 +141,7 @@ describe('CurrentBoardApproved Component', () => { it('should render correctly for single person', () => { const { queryByText, queryByRole, getAllByText } = render( - , + , ); expect(queryByText('Current Board Approved MHA')).toBeInTheDocument(); @@ -141,42 +165,19 @@ describe('CurrentBoardApproved Component', () => { it('should navigate to edit page with new requestId after duplicate mutation', async () => { const { getByText } = render( - - - - mocks={{ - DuplicateMinistryHousingAllowanceRequest: { - duplicateMinistryHousingAllowanceRequest: { - ministryHousingAllowanceRequest: { - id: newRequestId, - }, - }, + - - - - - - , + }, + }, + }} + />, ); const updateButton = getByText('Update Current MHA'); @@ -199,4 +200,39 @@ describe('CurrentBoardApproved Component', () => { ); }); }); + + it('should handle duplicate mutation error gracefully without throwing', async () => { + const { getByText } = render( + , + ); + + const updateButton = getByText('Update Current MHA'); + userEvent.click(updateButton); + + await waitFor(() => { + expect(mockPush).not.toHaveBeenCalled(); + }); + }); }); From 56722a7037db73c3893b99be7688543232b84081 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:51:17 -0500 Subject: [PATCH 3/6] Remove unhelpful test --- .../CurrentBoardApproved.test.tsx | 73 +++---------------- 1 file changed, 12 insertions(+), 61 deletions(-) diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx index 5a57652000..b79002c45a 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx @@ -1,17 +1,12 @@ import React from 'react'; -import { MockedProvider, MockedResponse } from '@apollo/client/testing'; import { ThemeProvider } from '@mui/material/styles'; import { render, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { GraphQLError } from 'graphql'; import { DeepPartial } from 'ts-essentials'; import TestRouter from '__tests__/util/TestRouter'; import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; import theme from 'src/theme'; -import { - DuplicateMinistryHousingAllowanceRequestDocument, - DuplicateMinistryHousingAllowanceRequestMutation, -} from '../MinisterHousingAllowance.generated'; +import { DuplicateMinistryHousingAllowanceRequestMutation } from '../MinisterHousingAllowance.generated'; import { ContextType, HcmData, @@ -46,7 +41,6 @@ interface TestComponentProps { mocks?: DeepPartial<{ DuplicateMinistryHousingAllowanceRequest: DuplicateMinistryHousingAllowanceRequestMutation; }>; - errorMocks?: MockedResponse[]; } const TestComponent: React.FC = ({ @@ -54,7 +48,6 @@ const TestComponent: React.FC = ({ request, router = {}, mocks, - errorMocks, }) => { const approvedMHARequest = request ?? { ...mockMHARequest, @@ -68,29 +61,21 @@ const TestComponent: React.FC = ({ }, }; - const content = ( - - - - ); - return ( - {errorMocks ? ( - {content} - ) : ( - - mocks={mocks} - onCall={mutationSpy} + + mocks={mocks} + onCall={mutationSpy} + > + - {content} - - )} + + + ); @@ -201,38 +186,4 @@ describe('CurrentBoardApproved Component', () => { }); }); - it('should handle duplicate mutation error gracefully without throwing', async () => { - const { getByText } = render( - , - ); - - const updateButton = getByText('Update Current MHA'); - userEvent.click(updateButton); - - await waitFor(() => { - expect(mockPush).not.toHaveBeenCalled(); - }); - }); }); From 96aaf7c571a5fb069d7703f34c9a07fafc017ea4 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:52:41 -0500 Subject: [PATCH 4/6] Remove unnecessary blank line at the end of CurrentBoardApproved.test.tsx --- .../SharedComponents/CurrentBoardApproved.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx index b79002c45a..56f7e83822 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx @@ -185,5 +185,4 @@ describe('CurrentBoardApproved Component', () => { ); }); }); - }); From 7c8c20deaf662a03fefbbbc8df5e5f205d31f5f6 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 16:32:20 -0500 Subject: [PATCH 5/6] Add hasOpenRequest prop to CurrentBoardApproved component and update tests --- .../MinisterHousingAllowance.tsx | 5 ++++- .../CurrentBoardApproved.test.tsx | 16 +++++++++++++++- .../SharedComponents/CurrentBoardApproved.tsx | 5 +++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.tsx b/src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.tsx index d74a4f67be..bdb0b1b1e9 100644 --- a/src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.tsx +++ b/src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.tsx @@ -181,7 +181,10 @@ export const MinisterHousingAllowanceReport = () => { )} {showPreviousRequests && ( - + )} diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx index 56f7e83822..30597486ce 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx @@ -41,6 +41,7 @@ interface TestComponentProps { mocks?: DeepPartial<{ DuplicateMinistryHousingAllowanceRequest: DuplicateMinistryHousingAllowanceRequestMutation; }>; + hasOpenRequest?: boolean; } const TestComponent: React.FC = ({ @@ -48,6 +49,7 @@ const TestComponent: React.FC = ({ request, router = {}, mocks, + hasOpenRequest, }) => { const approvedMHARequest = request ?? { ...mockMHARequest, @@ -73,7 +75,10 @@ const TestComponent: React.FC = ({ - + @@ -185,4 +190,13 @@ describe('CurrentBoardApproved Component', () => { ); }); }); + + it('should hide Update Current MHA button when there is an open request', () => { + const { queryByText, getByText } = render( + , + ); + + expect(getByText('View Current MHA')).toBeInTheDocument(); + expect(queryByText('Update Current MHA')).not.toBeInTheDocument(); + }); }); diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx index 9ea077ad0f..4623dc5e7d 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.tsx @@ -24,10 +24,12 @@ import { MHARequest } from './types'; interface CurrentBoardApprovedProps { request: MHARequest | null; + hasOpenRequest?: boolean; } export const CurrentBoardApproved: React.FC = ({ request, + hasOpenRequest = false, }) => { const { t } = useTranslation(); const locale = useLocale(); @@ -68,8 +70,6 @@ export const CurrentBoardApproved: React.FC = ({ router.push(getRequestUrl(accountListId, newRequestId, 'edit')); } }, - // Prevents unhandled promise rejection - onError: () => {}, }); }; @@ -92,6 +92,7 @@ export const CurrentBoardApproved: React.FC = ({ linkOne={viewLink} linkTwoText={t('Update Current MHA')} handleLinkTwo={handleDuplicateRequest} + hideLinkTwoButton={hasOpenRequest} isRequest={false} handlePrint={handlePrint} handleConfirmCancel={() => {}} From 70acc5ffdaf6f43a0d52574184cdfc4ef2fb9106 Mon Sep 17 00:00:00 2001 From: zachery with an e <45150570+zweatshirt@users.noreply.github.com> Date: Mon, 16 Mar 2026 17:44:11 -0500 Subject: [PATCH 6/6] Run prettier --- .../SharedComponents/CurrentBoardApproved.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx index 30597486ce..43d080d64b 100644 --- a/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx +++ b/src/components/Reports/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx @@ -192,9 +192,7 @@ describe('CurrentBoardApproved Component', () => { }); it('should hide Update Current MHA button when there is an open request', () => { - const { queryByText, getByText } = render( - , - ); + const { queryByText, getByText } = render(); expect(getByText('View Current MHA')).toBeInTheDocument(); expect(queryByText('Update Current MHA')).not.toBeInTheDocument();