Skip to content

Commit 0eab8a6

Browse files
committed
Initial commit to integrate MHA eligibility: add HCM EIT checks and modify tests
1 parent 6240f2d commit 0eab8a6

7 files changed

Lines changed: 85 additions & 65 deletions

File tree

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,61 @@
11
import React from 'react';
22
import { ThemeProvider } from '@mui/material/styles';
3-
import { LocalizationProvider } from '@mui/x-date-pickers';
4-
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
53
import { render } from '@testing-library/react';
4+
import TestRouter from '__tests__/util/TestRouter';
5+
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
66
import theme from 'src/theme';
7+
import { HcmDataQuery } from '../../Shared/HcmData/HCMData.generated';
78
import {
8-
ContextType,
9-
HcmData,
10-
MinisterHousingAllowanceContext,
11-
} from '../Shared/Context/MinisterHousingAllowanceContext';
9+
marriedSpouseIneligible,
10+
singleNoMhaNoException,
11+
} from '../../Shared/HcmData/mockData';
12+
import { MinistryHousingAllowanceRequestsQuery } from '../MinisterHousingAllowance.generated';
13+
import { MinisterHousingAllowanceProvider } from '../Shared/Context/MinisterHousingAllowanceContext';
1214
import { IneligibleDisplay } from './IneligibleDisplay';
1315

1416
interface TestComponentProps {
15-
contextValue: Partial<ContextType>;
17+
hcmMock: HcmDataQuery['hcm'];
1618
}
1719

18-
const TestComponent: React.FC<TestComponentProps> = ({ contextValue }) => {
20+
const TestComponent: React.FC<TestComponentProps> = ({ hcmMock }) => {
1921
return (
2022
<ThemeProvider theme={theme}>
21-
<LocalizationProvider dateAdapter={AdapterLuxon}>
22-
<MinisterHousingAllowanceContext.Provider
23-
value={contextValue as ContextType}
23+
<TestRouter>
24+
<GqlMockedProvider<{
25+
HcmData: HcmDataQuery;
26+
MinistryHousingAllowanceRequests: MinistryHousingAllowanceRequestsQuery;
27+
}>
28+
mocks={{
29+
HcmData: {
30+
hcm: hcmMock,
31+
},
32+
MinistryHousingAllowanceRequests: {
33+
ministryHousingAllowanceRequests: {
34+
nodes: [],
35+
},
36+
},
37+
}}
2438
>
25-
<IneligibleDisplay />
26-
</MinisterHousingAllowanceContext.Provider>
27-
</LocalizationProvider>
39+
<MinisterHousingAllowanceProvider>
40+
<IneligibleDisplay />
41+
</MinisterHousingAllowanceProvider>
42+
</GqlMockedProvider>
43+
</TestRouter>
2844
</ThemeProvider>
2945
);
3046
};
3147

3248
describe('IneligibleDisplay', () => {
33-
it('should render page with single staff', () => {
34-
const { getByText, queryByText } = render(
35-
<TestComponent
36-
contextValue={{
37-
isMarried: false,
38-
preferredName: 'John',
39-
spousePreferredName: '',
40-
userHcmData: {
41-
staffInfo: {
42-
personNumber: '000123456',
43-
},
44-
} as unknown as HcmData,
45-
spouseHcmData: null,
46-
}}
47-
/>,
49+
it('should render page with single staff', async () => {
50+
const { findByRole, findByText, queryByText } = render(
51+
<TestComponent hcmMock={singleNoMhaNoException} />,
4852
);
4953

50-
expect(getByText('Your MHA')).toBeInTheDocument();
5154
expect(
52-
getByText(
55+
await findByRole('heading', { name: 'Your MHA' }),
56+
).toBeInTheDocument();
57+
expect(
58+
await findByText(
5359
/our records indicate that you have not applied for minister's housing allowance/i,
5460
),
5561
).toBeInTheDocument();
@@ -58,29 +64,16 @@ describe('IneligibleDisplay', () => {
5864
).not.toBeInTheDocument();
5965
});
6066

61-
it('should render page with married staff', () => {
62-
const { getByText } = render(
63-
<TestComponent
64-
contextValue={{
65-
isMarried: true,
66-
preferredName: 'John',
67-
spousePreferredName: 'Jane',
68-
userHcmData: {
69-
staffInfo: {
70-
personNumber: '000123456',
71-
},
72-
} as unknown as HcmData,
73-
spouseHcmData: {
74-
staffInfo: {
75-
personNumber: '100123456',
76-
},
77-
} as unknown as HcmData,
78-
}}
79-
/>,
67+
it('should render page with married staff and ineligible spouse', async () => {
68+
const { findByRole, findByText } = render(
69+
<TestComponent hcmMock={marriedSpouseIneligible} />,
8070
);
8171

8272
expect(
83-
getByText(/Jane has not completed the required ibs courses/i),
73+
await findByRole('heading', { name: 'Your MHA' }),
74+
).toBeInTheDocument();
75+
expect(
76+
await findByText(/Jane has not completed the required ibs courses/i),
8477
).toBeInTheDocument();
8578
});
8679
});

src/components/Reports/MinisterHousingAllowance/MainPages/IneligibleDisplay.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import { useMinisterHousingAllowance } from '../Shared/Context/MinisterHousingAl
44

55
export const IneligibleDisplay: React.FC = () => {
66
const { t } = useTranslation();
7-
const { isMarried, preferredName, spousePreferredName } =
7+
const { isMarried, preferredName, spousePreferredName, spouseEligibleForMHA } =
88
useMinisterHousingAllowance();
99

10-
// TODO - Add spouse to API and check eligibility
11-
// We will get this from HCM data in the future
12-
const spouseEligibleForMHA = false;
13-
1410
return (
1511
<>
1612
<Box mb={2}>

src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import theme from 'src/theme';
99
import { HcmDataQuery } from '../Shared/HcmData/HCMData.generated';
1010
import {
1111
marriedMhaAndNoException,
12-
marriedNoMhaNoException,
12+
marriedSpouseIneligible,
1313
singleMhaNoException,
1414
singleNoMhaNoException,
1515
} from '../Shared/HcmData/mockData';
@@ -66,9 +66,9 @@ describe('MinisterHousingAllowanceReport', () => {
6666
expect(await findByText('John Doe')).toBeInTheDocument();
6767
});
6868

69-
it('renders married, no pending, no approved correctly', async () => {
69+
it('renders married with ineligible spouse, no approved requests', async () => {
7070
const { findByText } = render(
71-
<TestComponent hcmMock={marriedNoMhaNoException} mhaRequestsMock={[]} />,
71+
<TestComponent hcmMock={marriedSpouseIneligible} mhaRequestsMock={[]} />,
7272
);
7373

7474
expect(

src/components/Reports/MinisterHousingAllowance/MinisterHousingAllowance.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const MinisterHousingAllowanceReport = () => {
3131
spousePreferredName,
3232
userHcmData,
3333
spouseHcmData,
34+
canAccessMHA,
3435
requestsData,
3536
requestsError,
3637
} = useMinisterHousingAllowance();
@@ -118,21 +119,22 @@ export const MinisterHousingAllowanceReport = () => {
118119
) : (
119120
<>
120121
<Stack direction="column" width={mainContentWidth}>
121-
{hasNoRequests ? (
122+
{hasNoRequests || !canAccessMHA ? (
122123
<IneligibleDisplay />
123124
) : (
124125
<EligibleDisplay isPending={isCurrentRequestPending} />
125126
)}
126127
<NameDisplay names={names} personNumbers={personNumbers} />
127128

128-
{currentRequest &&
129+
{canAccessMHA &&
130+
currentRequest &&
129131
(isCurrentRequestPending ? (
130132
<CurrentRequest request={currentRequest} />
131133
) : (
132134
<CurrentBoardApproved request={currentRequest} />
133135
))}
134136
</Stack>
135-
{(!isCurrentRequestPending || hasNoRequests) && (
137+
{canAccessMHA && (!isCurrentRequestPending || hasNoRequests) && (
136138
<Button
137139
variant="contained"
138140
color="primary"
@@ -145,7 +147,7 @@ export const MinisterHousingAllowanceReport = () => {
145147
</>
146148
)}
147149

148-
{previousApprovedRequest && (
150+
{canAccessMHA && previousApprovedRequest && (
149151
<Stack direction="column" width={mainContentWidth} mt={4}>
150152
<CurrentBoardApproved request={previousApprovedRequest} />
151153
</Stack>

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export type ContextType = {
5353
spouseHcmData?: HcmData | null;
5454
preferredName: string;
5555
spousePreferredName: string;
56+
spouseEligibleForMHA: boolean;
57+
canAccessMHA: boolean;
5658

5759
requestData?:
5860
| MinistryHousingAllowanceRequestQuery['ministryHousingAllowanceRequest']
@@ -97,8 +99,7 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
9799
const { data: requestsData, error: requestsError } =
98100
useMinistryHousingAllowanceRequestsQuery();
99101

100-
//const requestId = requestsData?.ministryHousingAllowanceRequests.nodes[0]?.id;
101-
const requestId = 'c1a68821-5fb6-4e5e-b308-9263539af9d8';
102+
const requestId = requestsData?.ministryHousingAllowanceRequests.nodes[0]?.id;
102103

103104
const { data: requestData, error: requestError } =
104105
useMinistryHousingAllowanceRequestQuery({
@@ -169,6 +170,14 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
169170
[spouseHcmData],
170171
);
171172

173+
const { canAccessMHA, spouseEligibleForMHA } = useMemo(() => {
174+
const userEligible = userHcmData?.mhaEit?.mhaEligibility ?? false;
175+
const spouseEligible = spouseHcmData?.mhaEit?.mhaEligibility ?? false;
176+
// Allow access if at least one person is eligible (user OR spouse if married)
177+
const canAccess = userEligible || (isMarried && spouseEligible);
178+
return { canAccessMHA: canAccess, spouseEligibleForMHA: spouseEligible };
179+
}, [userHcmData, spouseHcmData, isMarried]);
180+
172181
const [isDrawerOpen, setIsDrawerOpen] = useState(true);
173182
const toggleDrawer = useCallback(() => {
174183
setIsDrawerOpen((prev) => !prev);
@@ -212,6 +221,8 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
212221
spouseHcmData,
213222
preferredName,
214223
spousePreferredName,
224+
spouseEligibleForMHA,
225+
canAccessMHA,
215226
isPrint,
216227
setIsPrint,
217228
setIsComplete,
@@ -241,6 +252,8 @@ export const MinisterHousingAllowanceProvider: React.FC<Props> = ({
241252
spouseHcmData,
242253
preferredName,
243254
spousePreferredName,
255+
spouseEligibleForMHA,
256+
canAccessMHA,
244257
isPrint,
245258
setIsPrint,
246259
setIsComplete,

src/components/Reports/Shared/HcmData/HCMData.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ query HcmData($maritalStatus: MaritalStatusEnum!) {
2929
lastUpdatedDate
3030
currentApprovedAmountForStaff
3131
}
32+
mhaEit {
33+
mhaEligibility
34+
}
3235
exceptionSalaryCap {
3336
amount
3437
effectiveDate

src/components/Reports/Shared/HcmData/mockData.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const noMhaAndNoException: HcmDataQuery['hcm'][0] = {
4646
lastUpdatedDate: null,
4747
currentApprovedAmountForStaff: null,
4848
},
49+
mhaEit: {
50+
mhaEligibility: true,
51+
},
4952
exceptionSalaryCap: {
5053
amount: null,
5154
effectiveDate: null,
@@ -106,3 +109,13 @@ export const marriedNoMhaNoException: HcmDataQuery['hcm'] = [
106109
staffInfo: janeDoe,
107110
},
108111
];
112+
export const marriedSpouseIneligible: HcmDataQuery['hcm'] = [
113+
noMhaAndNoException,
114+
{
115+
...noMhaAndNoException,
116+
staffInfo: janeDoe,
117+
mhaEit: {
118+
mhaEligibility: false,
119+
},
120+
},
121+
];

0 commit comments

Comments
 (0)