Skip to content

Commit a89ee63

Browse files
committed
Merge branch 'MPDX-9613' into staging
2 parents 8cc32e5 + 7663059 commit a89ee63

15 files changed

Lines changed: 309 additions & 205 deletions

File tree

pages/accountLists/[accountListId]/hrTools/goalCalculator/[goalCalculationId].page.test.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1+
import React from 'react';
12
import TestRouter from '__tests__/util/TestRouter';
23
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
34
import { render } from '__tests__/util/testingLibraryReactMock';
45
import { blockImpersonatingNonDevelopers } from 'pages/api/utils/pagePropsHelpers';
6+
import { HcmQuery } from 'src/components/HrTools/Shared/HcmData/Hcm.generated';
57
import { GetUserQuery } from 'src/components/User/GetUser.generated';
6-
import { UserTypeEnum } from 'src/graphql/types.generated';
8+
import {
9+
PeopleGroupSupportTypeEnum,
10+
UserTypeEnum,
11+
} from 'src/graphql/types.generated';
712
import {
813
GoalCalculatorPage,
914
getServerSideProps,
1015
} from './[goalCalculationId].page';
1116

12-
const Components = () => (
17+
interface ComponentsProps {
18+
userType?: UserTypeEnum;
19+
peopleGroupSupportType?: PeopleGroupSupportTypeEnum;
20+
salaryRequestEligible?: boolean;
21+
}
22+
23+
const Components: React.FC<ComponentsProps> = ({
24+
userType = UserTypeEnum.NonCru,
25+
peopleGroupSupportType = PeopleGroupSupportTypeEnum.SupportedRmo,
26+
salaryRequestEligible = true,
27+
}) => (
1328
<TestRouter>
1429
<GqlMockedProvider<{
1530
GetUser: GetUserQuery;
31+
Hcm: HcmQuery;
1632
}>
1733
mocks={{
18-
GetUser: { user: { userType: UserTypeEnum.NonCru } },
34+
GetUser: { user: { userType } },
35+
Hcm: {
36+
hcm: [
37+
{
38+
salaryRequestEligible,
39+
staffInfo: { peopleGroupSupportType },
40+
},
41+
],
42+
},
1943
}}
2044
>
2145
<GoalCalculatorPage />
@@ -35,4 +59,18 @@ describe('[goalCalculationId] page', () => {
3559
await findByText('Access to this feature is limited.'),
3660
).toBeInTheDocument();
3761
});
62+
63+
it('should show limited access for a US Staff user whose peopleGroupSupportType is Designation (PDS)', async () => {
64+
const { findByText } = render(
65+
<Components
66+
userType={UserTypeEnum.UsStaff}
67+
peopleGroupSupportType={PeopleGroupSupportTypeEnum.Designation}
68+
salaryRequestEligible={false}
69+
/>,
70+
);
71+
72+
expect(
73+
await findByText('Access to this feature is limited.'),
74+
).toBeInTheDocument();
75+
});
3876
});

pages/accountLists/[accountListId]/hrTools/goalCalculator/[goalCalculationId].page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import {
2323
MultiPageMenu,
2424
NavTypeEnum,
2525
} from 'src/components/Shared/MultiPageLayout/MultiPageMenu/MultiPageMenu';
26-
import { UserTypeAccess } from 'src/components/Shared/UserTypeAccess/UserTypeAccess';
26+
import {
27+
RequiredUserGroupEnum,
28+
UserTypeAccess,
29+
} from 'src/components/Shared/UserTypeAccess/UserTypeAccess';
2730
import { ReportPageWrapper } from 'src/components/Shared/styledComponents/ReportPageWrapper';
2831
import { useAccountListId } from 'src/hooks/useAccountListId';
2932
import { getAppName } from 'src/lib/getAppName';
@@ -139,7 +142,7 @@ export const GoalCalculatorPage: React.FC = () => {
139142
<title>{`${appName} | ${t('Reports - Goal Calculation')}`}</title>
140143
</Head>
141144
{accountListId ? (
142-
<UserTypeAccess>
145+
<UserTypeAccess requireUserGroups={RequiredUserGroupEnum.MpdGoalCalc}>
143146
<ReportPageWrapper>
144147
<GoalCalculatorProvider>
145148
<GoalCalculatorContent

pages/accountLists/[accountListId]/hrTools/goalCalculator/index.page.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import { GoalCalculatorPage, getServerSideProps } from './index.page';
1313
interface ComponentsProps {
1414
userType?: UserTypeEnum;
1515
peopleGroupSupportType?: PeopleGroupSupportTypeEnum;
16+
salaryRequestEligible?: boolean;
1617
}
1718

1819
const Components: React.FC<ComponentsProps> = ({
1920
userType = UserTypeEnum.NonCru,
2021
peopleGroupSupportType = PeopleGroupSupportTypeEnum.SupportedRmo,
22+
salaryRequestEligible = true,
2123
}) => (
2224
<TestRouter>
2325
<GqlMockedProvider<{
@@ -29,6 +31,7 @@ const Components: React.FC<ComponentsProps> = ({
2931
Hcm: {
3032
hcm: [
3133
{
34+
salaryRequestEligible,
3235
staffInfo: { peopleGroupSupportType },
3336
},
3437
],
@@ -58,6 +61,7 @@ describe('GoalCalculator page', () => {
5861
<Components
5962
userType={UserTypeEnum.UsStaff}
6063
peopleGroupSupportType={PeopleGroupSupportTypeEnum.Designation}
64+
salaryRequestEligible={false}
6165
/>,
6266
);
6367

pages/accountLists/[accountListId]/hrTools/pdsGoalCalculator/[pdsGoalId].page.test.tsx

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,78 @@
11
import React from 'react';
2-
import { render } from '@testing-library/react';
2+
import TestRouter from '__tests__/util/TestRouter';
3+
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
4+
import { render } from '__tests__/util/testingLibraryReactMock';
35
import { blockImpersonatingNonDevelopers } from 'pages/api/utils/pagePropsHelpers';
46
import { PdsGoalCalculatorTestWrapper } from 'src/components/HrTools/PdsGoalCalculator/PdsGoalCalculatorTestWrapper';
7+
import { HcmQuery } from 'src/components/HrTools/Shared/HcmData/Hcm.generated';
8+
import { GetUserQuery } from 'src/components/User/GetUser.generated';
9+
import { UserTypeEnum } from 'src/graphql/types.generated';
510
import { PdsGoalCalculatorPage, getServerSideProps } from './[pdsGoalId].page';
611

12+
interface AccessComponentsProps {
13+
userType?: UserTypeEnum;
14+
designationSupportCalculatorEligible?: boolean;
15+
}
16+
17+
const AccessComponents: React.FC<AccessComponentsProps> = ({
18+
userType = UserTypeEnum.UsStaff,
19+
designationSupportCalculatorEligible = true,
20+
}) => (
21+
<TestRouter>
22+
<GqlMockedProvider<{
23+
GetUser: GetUserQuery;
24+
Hcm: HcmQuery;
25+
}>
26+
mocks={{
27+
GetUser: { user: { userType } },
28+
Hcm: {
29+
hcm: [{ designationSupportCalculatorEligible }],
30+
},
31+
}}
32+
>
33+
<PdsGoalCalculatorPage />
34+
</GqlMockedProvider>
35+
</TestRouter>
36+
);
37+
738
describe('[pdsGoalId] page', () => {
839
it('uses blockImpersonatingNonDevelopers for server-side props', () => {
940
expect(getServerSideProps).toBe(blockImpersonatingNonDevelopers);
1041
});
1142

12-
it('renders Saving indicator', async () => {
43+
it('should show limited access for a non-Cru user', async () => {
44+
const { findByText } = render(
45+
<AccessComponents userType={UserTypeEnum.NonCru} />,
46+
);
47+
48+
expect(
49+
await findByText('Access to this feature is limited.'),
50+
).toBeInTheDocument();
51+
});
52+
53+
it('should show limited access when designationSupportCalculatorEligible is false', async () => {
54+
const { findByText } = render(
55+
<AccessComponents designationSupportCalculatorEligible={false} />,
56+
);
57+
58+
expect(
59+
await findByText('Access to this feature is limited.'),
60+
).toBeInTheDocument();
61+
});
62+
63+
it('renders Saving indicator for an eligible US Staff user', async () => {
1364
const { findByText } = render(
14-
<PdsGoalCalculatorTestWrapper withProvider={false}>
65+
<PdsGoalCalculatorTestWrapper<{
66+
Hcm: HcmQuery;
67+
}>
68+
withProvider={false}
69+
userMock={{ user: { userType: UserTypeEnum.UsStaff } }}
70+
extraMocks={{
71+
Hcm: {
72+
hcm: [{ designationSupportCalculatorEligible: true }],
73+
},
74+
}}
75+
>
1576
<PdsGoalCalculatorPage />
1677
</PdsGoalCalculatorTestWrapper>,
1778
);

pages/accountLists/[accountListId]/hrTools/pdsGoalCalculator/[pdsGoalId].page.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
MultiPageMenu,
2323
NavTypeEnum,
2424
} from 'src/components/Shared/MultiPageLayout/MultiPageMenu/MultiPageMenu';
25+
import {
26+
RequiredUserGroupEnum,
27+
UserTypeAccess,
28+
} from 'src/components/Shared/UserTypeAccess/UserTypeAccess';
2529
import { ReportPageWrapper } from 'src/components/Shared/styledComponents/ReportPageWrapper';
2630
import { useAccountListId } from 'src/hooks/useAccountListId';
2731
import { getAppName } from 'src/lib/getAppName';
@@ -139,16 +143,18 @@ export const PdsGoalCalculatorPage: React.FC = () => {
139143
<title>{`${appName} | ${t('HR Tools - Paid with Designation Support Goal Calculator')}`}</title>
140144
</Head>
141145
{accountListId ? (
142-
<ReportPageWrapper>
143-
<PdsGoalCalculatorProvider>
144-
<PdsGoalCalculatorContent
145-
isNavListOpen={isNavListOpen}
146-
onNavListToggle={handleNavListToggle}
147-
designationAccounts={designationAccounts}
148-
setDesignationAccounts={setDesignationAccounts}
149-
/>
150-
</PdsGoalCalculatorProvider>
151-
</ReportPageWrapper>
146+
<UserTypeAccess requireUserGroups={RequiredUserGroupEnum.PdsGoalCalc}>
147+
<ReportPageWrapper>
148+
<PdsGoalCalculatorProvider>
149+
<PdsGoalCalculatorContent
150+
isNavListOpen={isNavListOpen}
151+
onNavListToggle={handleNavListToggle}
152+
designationAccounts={designationAccounts}
153+
setDesignationAccounts={setDesignationAccounts}
154+
/>
155+
</PdsGoalCalculatorProvider>
156+
</ReportPageWrapper>
157+
</UserTypeAccess>
152158
) : (
153159
<Loading loading />
154160
)}

src/components/HrTools/Shared/HcmData/Hcm.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ query Hcm($effectiveDate: ISO8601Date) {
5252
currentTakenAmount
5353
}
5454
salaryRequestEligible
55+
designationSupportCalculatorEligible
5556
}
5657
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const janeDoe: HcmQuery['hcm'][number]['staffInfo'] = {
3030

3131
const noMhaAndNoException: HcmQuery['hcm'][number] = {
3232
salaryRequestEligible: true,
33+
designationSupportCalculatorEligible: false,
3334
staffInfo: johnDoe,
3435
mhaRequest: {
3536
currentApprovedOverallAmount: null,

src/components/HrTools/StaffSavingFund/StaffSavingFundLayout.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const Components: React.FC<ComponentProps> = ({
7171
asrEit: {
7272
asrEligibility: true,
7373
},
74+
salaryRequestEligible: true,
75+
designationSupportCalculatorEligible: true,
7476
},
7577
],
7678
},

src/components/Shared/MultiPageLayout/MultiPageMenu/MultiPageMenu.test.tsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ describe('MultiPageMenu', () => {
517517
},
518518
asrEit: { asrEligibility: true },
519519
salaryRequestEligible: true,
520+
designationSupportCalculatorEligible: true,
520521
},
521522
],
522523
},
@@ -540,22 +541,23 @@ describe('MultiPageMenu', () => {
540541
expect(getByText('MPD Goal Calculator')).toBeInTheDocument();
541542
expect(getByText('MHA Calculation Tool')).toBeInTheDocument();
542543
expect(getByText('Additional Salary Request')).toBeInTheDocument();
544+
expect(
545+
getByText('Paid with Designation Support Goal Calculator'),
546+
).toBeInTheDocument();
543547
expect(getByText('Ministry Partner Reminders')).toBeInTheDocument();
544548
});
545549

546-
it('hides the PDS Goal Calculator nav item for SupportedRmo (senior) staff', async () => {
547-
const { findByText, getByText, queryByText } = render(
550+
it('hides MPD Goal Calculator when salaryRequestEligible is false', async () => {
551+
const { findByText, queryByText } = render(
548552
<ThemeProvider theme={theme}>
549553
<TestRouter router={router}>
550554
<GqlMockedProvider<{ Hcm: HcmQuery }>
551555
mocks={{
552556
Hcm: {
553557
hcm: [
554558
{
555-
staffInfo: {
556-
peopleGroupSupportType:
557-
PeopleGroupSupportTypeEnum.SupportedRmo,
558-
},
559+
salaryRequestEligible: false,
560+
designationSupportCalculatorEligible: true,
559561
},
560562
],
561563
},
@@ -574,27 +576,23 @@ describe('MultiPageMenu', () => {
574576
</ThemeProvider>,
575577
);
576578

577-
expect(await findByText('MPD Goal Calculator')).toBeInTheDocument();
578579
expect(
579-
queryByText('Paid with Designation Support Goal Calculator'),
580-
).not.toBeInTheDocument();
581-
expect(getByText('Savings Fund Transfer')).toBeInTheDocument();
582-
expect(getByText('Ministry Partner Reminders')).toBeInTheDocument();
580+
await findByText('Paid with Designation Support Goal Calculator'),
581+
).toBeInTheDocument();
582+
expect(queryByText('MPD Goal Calculator')).not.toBeInTheDocument();
583583
});
584584

585-
it('hides the MPD Goal Calculator nav item for Designation (PDS) staff', async () => {
586-
const { findByText, getByText, queryByText } = render(
585+
it('hides PDS Goal Calculator when designationSupportCalculatorEligible is false', async () => {
586+
const { findByText, queryByText } = render(
587587
<ThemeProvider theme={theme}>
588588
<TestRouter router={router}>
589589
<GqlMockedProvider<{ Hcm: HcmQuery }>
590590
mocks={{
591591
Hcm: {
592592
hcm: [
593593
{
594-
staffInfo: {
595-
peopleGroupSupportType:
596-
PeopleGroupSupportTypeEnum.Designation,
597-
},
594+
salaryRequestEligible: true,
595+
designationSupportCalculatorEligible: false,
598596
},
599597
],
600598
},
@@ -613,11 +611,9 @@ describe('MultiPageMenu', () => {
613611
</ThemeProvider>,
614612
);
615613

614+
expect(await findByText('MPD Goal Calculator')).toBeInTheDocument();
616615
expect(
617-
await findByText('Paid with Designation Support Goal Calculator'),
618-
).toBeInTheDocument();
619-
expect(queryByText('MPD Goal Calculator')).not.toBeInTheDocument();
620-
expect(getByText('Savings Fund Transfer')).toBeInTheDocument();
621-
expect(getByText('Ministry Partner Reminders')).toBeInTheDocument();
616+
queryByText('Paid with Designation Support Goal Calculator'),
617+
).not.toBeInTheDocument();
622618
});
623619
});

src/components/Shared/MultiPageLayout/MultiPageMenu/MultiPageMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const MultiPageMenu: React.FC<Props & BoxProps> = ({
100100
const accountListId = useAccountListId();
101101
const user = useRequiredSession();
102102
const reportNavItems = useReportNavItems();
103-
const hrToolsNavItems = useHrToolsNavItems();
103+
const { items: hrToolsNavItems } = useHrToolsNavItems();
104104
const settingsNavItems = useSettingsNavItems();
105105

106106
const navItems =

0 commit comments

Comments
 (0)