Skip to content

Commit e28928d

Browse files
authored
Merge pull request #1824 from CruGlobal/MPDX-9327-disable-update-mha
MPDX-9327, MPDX-9670 - Fix MHA "Update Current MHA" button visibility and taken/approved amounts displays
2 parents 2cedf39 + 3f6c3d1 commit e28928d

6 files changed

Lines changed: 203 additions & 30 deletions

File tree

src/components/HrTools/MinisterHousingAllowance/MinisterHousingAllowance.test.tsx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe('MinisterHousingAllowanceReport', () => {
297297
<TestComponent
298298
hcmMock={singleMhaNoException}
299299
mhaRequestsMock={[
300-
{ ...mockMHARequest, status: MhaStatusEnum.BoardApproved },
300+
{ ...mockMHARequest, status: MhaStatusEnum.HrApproved },
301301
]}
302302
/>,
303303
);
@@ -320,21 +320,34 @@ describe('MinisterHousingAllowanceReport', () => {
320320
});
321321
});
322322

323-
it.each([
324-
MhaStatusEnum.HrApproved,
325-
MhaStatusEnum.BoardApproved,
326-
MhaStatusEnum.Cancelled,
327-
])('shows new request button when current request is %s', async (status) => {
328-
const { findByRole } = render(
323+
it.each([MhaStatusEnum.HrApproved, MhaStatusEnum.Cancelled])(
324+
'shows new request button when current request is %s',
325+
async (status) => {
326+
const { findByRole } = render(
327+
<TestComponent
328+
hcmMock={singleMhaNoException}
329+
mhaRequestsMock={[{ ...mockMHARequest, status }]}
330+
/>,
331+
);
332+
333+
expect(
334+
await findByRole('button', { name: 'Request New MHA' }),
335+
).toBeInTheDocument();
336+
},
337+
);
338+
339+
it('hides new request button when current request is board approved', async () => {
340+
const { findByText, queryByText } = render(
329341
<TestComponent
330342
hcmMock={singleMhaNoException}
331-
mhaRequestsMock={[{ ...mockMHARequest, status }]}
343+
mhaRequestsMock={[
344+
{ ...mockMHARequest, status: MhaStatusEnum.BoardApproved },
345+
]}
332346
/>,
333347
);
334348

335-
expect(
336-
await findByRole('button', { name: 'Request New MHA' }),
337-
).toBeInTheDocument();
349+
expect(await findByText('Current Board Approved MHA')).toBeInTheDocument();
350+
expect(queryByText('Request New MHA')).not.toBeInTheDocument();
338351
});
339352

340353
it.each([
@@ -356,12 +369,28 @@ describe('MinisterHousingAllowanceReport', () => {
356369
},
357370
);
358371

372+
it('hides Update Current MHA on the previous approved request while an open request exists', async () => {
373+
const { findByText, queryByText } = render(
374+
<TestComponent
375+
hcmMock={singleMhaNoException}
376+
mhaRequestsMock={[
377+
{ ...mockMHARequest, id: '1', status: MhaStatusEnum.InProgress },
378+
{ ...mockMHARequest, id: '2', status: MhaStatusEnum.BoardApproved },
379+
]}
380+
/>,
381+
);
382+
383+
expect(await findByText('Current Board Approved MHA')).toBeInTheDocument();
384+
expect(queryByText('View Current MHA')).toBeInTheDocument();
385+
expect(queryByText('Update Current MHA')).not.toBeInTheDocument();
386+
});
387+
359388
it('shows success snackbar when MHA request is created', async () => {
360389
const { findByText } = render(
361390
<TestComponent
362391
hcmMock={singleMhaNoException}
363392
mhaRequestsMock={[
364-
{ ...mockMHARequest, status: MhaStatusEnum.BoardApproved },
393+
{ ...mockMHARequest, status: MhaStatusEnum.HrApproved },
365394
]}
366395
/>,
367396
);

src/components/HrTools/MinisterHousingAllowance/MinisterHousingAllowance.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export const MinisterHousingAllowanceReport = () => {
127127

128128
const eitherPersonEligible = userEligibleForMHA || spouseEligibleForMHA;
129129

130-
const showNewRequestButton = eitherPersonEligible && !hasBlockingRequest;
130+
const hasCurrentBoardApprovedMha =
131+
currentRequest?.status === MhaStatusEnum.BoardApproved;
132+
const showNewRequestButton =
133+
eitherPersonEligible && !hasBlockingRequest && !hasCurrentBoardApprovedMha;
134+
131135
const showCurrentRequest = eitherPersonEligible && currentRequest;
132136
const showPreviousRequests = eitherPersonEligible && previousApprovedRequest;
133137

@@ -206,7 +210,10 @@ export const MinisterHousingAllowanceReport = () => {
206210
(isCurrentRequestPending ? (
207211
<CurrentRequest request={currentRequest} />
208212
) : (
209-
<CurrentBoardApproved request={currentRequest} />
213+
<CurrentBoardApproved
214+
request={currentRequest}
215+
hasOpenRequest={false}
216+
/>
210217
))}
211218
</Stack>
212219
{showNewRequestButton && (
@@ -221,7 +228,10 @@ export const MinisterHousingAllowanceReport = () => {
221228
)}
222229
{showPreviousRequests && (
223230
<Stack direction="column" width={mainContentWidth} mt={4}>
224-
<CurrentBoardApproved request={previousApprovedRequest} />
231+
<CurrentBoardApproved
232+
request={previousApprovedRequest}
233+
hasOpenRequest={isCurrentRequestPending}
234+
/>
225235
</Stack>
226236
)}
227237
</>

src/components/HrTools/MinisterHousingAllowance/Shared/Context/MinisterHousingAllowanceContext.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export type ContextType = {
5454
spousePreferredName: string;
5555
userEligibleForMHA: boolean;
5656
spouseEligibleForMHA: boolean;
57+
userApprovedOverallAmount: number | null;
58+
spouseApprovedOverallAmount: number | null;
59+
userTakenAmount: number | null;
60+
spouseTakenAmount: number | null;
5761
handleDiscard: () => Promise<void>;
5862

5963
requestData?:
@@ -204,6 +208,26 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
204208
[spouseHcmData],
205209
);
206210

211+
const userApprovedOverallAmount = useMemo(
212+
() => userHcmData?.mhaRequest.currentApprovedOverallAmount ?? null,
213+
[userHcmData],
214+
);
215+
216+
const spouseApprovedOverallAmount = useMemo(
217+
() => spouseHcmData?.mhaRequest.currentApprovedOverallAmount ?? null,
218+
[spouseHcmData],
219+
);
220+
221+
const userTakenAmount = useMemo(
222+
() => userHcmData?.mhaRequest.currentTakenAmount ?? null,
223+
[userHcmData],
224+
);
225+
226+
const spouseTakenAmount = useMemo(
227+
() => spouseHcmData?.mhaRequest.currentTakenAmount ?? null,
228+
[spouseHcmData],
229+
);
230+
207231
const [isDrawerOpen, setIsDrawerOpen] = useState(true);
208232
const toggleDrawer = useCallback(() => {
209233
setIsDrawerOpen((prev) => !prev);
@@ -234,6 +258,10 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
234258
spousePreferredName,
235259
userEligibleForMHA,
236260
spouseEligibleForMHA,
261+
userApprovedOverallAmount,
262+
spouseApprovedOverallAmount,
263+
userTakenAmount,
264+
spouseTakenAmount,
237265
handleDiscard,
238266
setIsComplete,
239267
requestData: requestData?.ministryHousingAllowanceRequest ?? null,
@@ -264,6 +292,10 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
264292
spousePreferredName,
265293
userEligibleForMHA,
266294
spouseEligibleForMHA,
295+
userApprovedOverallAmount,
296+
spouseApprovedOverallAmount,
297+
userTakenAmount,
298+
spouseTakenAmount,
267299
handleDiscard,
268300
requestData,
269301
requestError,

src/components/HrTools/MinisterHousingAllowance/SharedComponents/CurrentBoardApproved.test.tsx

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ interface TestComponentProps {
2323
push?: jest.Mock;
2424
query?: { accountListId?: string };
2525
};
26+
hasOpenRequest?: boolean;
2627
}
2728

2829
const TestComponent: React.FC<TestComponentProps> = ({
2930
contextValue,
3031
router = {},
32+
hasOpenRequest = false,
3133
}) => {
3234
const approvedMHARequest = {
3335
...mockMHARequest,
3436
updatedAt: '2022-12-01',
3537
requestAttributes: {
3638
...mockMHARequest.requestAttributes,
3739
hrApprovedAt: '2023-01-15',
38-
approvedOverallAmount: 1500,
39-
staffSpecific: 1000,
40-
spouseSpecific: 500,
4140
},
4241
};
4342

@@ -52,7 +51,10 @@ const TestComponent: React.FC<TestComponentProps> = ({
5251
<MinisterHousingAllowanceContext.Provider
5352
value={contextValue as ContextType}
5453
>
55-
<CurrentBoardApproved request={approvedMHARequest} />
54+
<CurrentBoardApproved
55+
request={approvedMHARequest}
56+
hasOpenRequest={hasOpenRequest}
57+
/>
5658
</MinisterHousingAllowanceContext.Provider>
5759
</GqlMockedProvider>
5860
</TestRouter>
@@ -68,6 +70,10 @@ describe('CurrentBoardApproved Component', () => {
6870
isMarried: true,
6971
preferredName: 'John',
7072
spousePreferredName: 'Jane',
73+
userApprovedOverallAmount: 1500,
74+
spouseApprovedOverallAmount: 1500,
75+
userTakenAmount: 1000,
76+
spouseTakenAmount: 500,
7177
userHcmData: {
7278
staffInfo: {
7379
personNumber: '000123456',
@@ -110,6 +116,8 @@ describe('CurrentBoardApproved Component', () => {
110116
isMarried: false,
111117
preferredName: 'John',
112118
spousePreferredName: '',
119+
userApprovedOverallAmount: 1500,
120+
userTakenAmount: 1000,
113121
userHcmData: {
114122
staffInfo: {
115123
personNumber: '000123456',
@@ -139,6 +147,55 @@ describe('CurrentBoardApproved Component', () => {
139147
expect(queryByText('Jane')).not.toBeInTheDocument();
140148
});
141149

150+
it('shows distinct per-person approved and claimed amounts from HCM', () => {
151+
const { getByText } = render(
152+
<TestComponent
153+
contextValue={{
154+
isMarried: true,
155+
preferredName: 'John',
156+
spousePreferredName: 'Jane',
157+
userApprovedOverallAmount: 2000,
158+
spouseApprovedOverallAmount: 800,
159+
userTakenAmount: 1200,
160+
spouseTakenAmount: 300,
161+
userHcmData: {
162+
staffInfo: { personNumber: '000123456' },
163+
} as unknown as HcmData,
164+
spouseHcmData: {
165+
staffInfo: { personNumber: '100123456' },
166+
} as unknown as HcmData,
167+
}}
168+
/>,
169+
);
170+
171+
// MHA Approved by Board (per person)
172+
expect(getByText('$2,000.00')).toBeInTheDocument();
173+
expect(getByText('$800.00')).toBeInTheDocument();
174+
// MHA Claimed in Salary (per person)
175+
expect(getByText('$1,200.00')).toBeInTheDocument();
176+
expect(getByText('$300.00')).toBeInTheDocument();
177+
});
178+
179+
it('renders $0.00 when HCM approved/claimed amounts are null', () => {
180+
const { getAllByText } = render(
181+
<TestComponent
182+
contextValue={{
183+
isMarried: false,
184+
preferredName: 'John',
185+
spousePreferredName: '',
186+
userApprovedOverallAmount: null,
187+
userTakenAmount: null,
188+
userHcmData: {
189+
staffInfo: { personNumber: '000123456' },
190+
} as unknown as HcmData,
191+
spouseHcmData: null,
192+
}}
193+
/>,
194+
);
195+
196+
expect(getAllByText('$0.00')).toHaveLength(2);
197+
});
198+
142199
it('should navigate to edit page with new requestId after duplicate mutation', async () => {
143200
const { getByText } = render(
144201
<ThemeProvider theme={theme}>
@@ -172,7 +229,10 @@ describe('CurrentBoardApproved Component', () => {
172229
} as ContextType
173230
}
174231
>
175-
<CurrentBoardApproved request={mockMHARequest} />
232+
<CurrentBoardApproved
233+
request={mockMHARequest}
234+
hasOpenRequest={false}
235+
/>
176236
</MinisterHousingAllowanceContext.Provider>
177237
</GqlMockedProvider>
178238
</TestRouter>
@@ -199,4 +259,26 @@ describe('CurrentBoardApproved Component', () => {
199259
);
200260
});
201261
});
262+
263+
it('should hide Update Current MHA button when there is an open request', () => {
264+
const { queryByText, getByText } = render(
265+
<TestComponent
266+
contextValue={{
267+
isMarried: false,
268+
preferredName: 'John',
269+
spousePreferredName: '',
270+
userHcmData: {
271+
staffInfo: {
272+
personNumber: '000123456',
273+
},
274+
} as unknown as HcmData,
275+
spouseHcmData: null,
276+
}}
277+
hasOpenRequest
278+
/>,
279+
);
280+
281+
expect(getByText('View Current MHA')).toBeInTheDocument();
282+
expect(queryByText('Update Current MHA')).not.toBeInTheDocument();
283+
});
202284
});

0 commit comments

Comments
 (0)