Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const MpdGoalAdminPage: React.FC = () => {
)}`}</title>
</Head>
{accountListId ? (
<UserTypeAccess requireUserGroups={RequiredUserGroupEnum.MpdGoalCalc}>
<UserTypeAccess
requireUserGroups={RequiredUserGroupEnum.NewStaffCohorts}
>
<ReportPageWrapper>
<MpdGoalAdminProvider>
<MpdGoalAdminContent />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { NewStaffGoalCalculationQuery } from 'src/components/HrTools/NsGoalCalcu
import { GetUserQuery } from 'src/components/User/GetUser.generated';
import {
NewStaffQuestionnaireMaritalStatusEnum,
UsStaffGroupEnum,
UserTypeEnum,
} from 'src/graphql/types.generated';
import { GoalCalculatorConstantsQuery } from 'src/hooks/goalCalculatorConstants.generated';
Expand All @@ -28,12 +27,12 @@ const mockBlockImpersonatingNonDevelopers =
>;

interface TestComponentProps {
/** Senior Staff is the group the MPD goal tools are open to. */
usStaffGroup?: UsStaffGroupEnum;
/** The MPD Goals team and MPD coordinators are the only ones let in. */
canViewNewStaffCohorts?: boolean;
}

const TestComponent: React.FC<TestComponentProps> = ({
usStaffGroup = UsStaffGroupEnum.SeniorStaff,
canViewNewStaffCohorts = true,
}) => (
<TestRouter
router={{
Expand All @@ -54,7 +53,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
GetUser: {
user: {
userType: UserTypeEnum.UsStaff,
usStaffGroup,
canViewNewStaffCohorts,
staffAccountId: 'staff-account-1',
},
},
Expand Down Expand Up @@ -91,9 +90,9 @@ describe('Scenario NsGoalCalculator page', () => {
).toBeInTheDocument();
});

it("denies a user outside the admin table's group", async () => {
it('denies a user without goals-team or coordinator access', async () => {
const { findByRole } = render(
<TestComponent usStaffGroup={UsStaffGroupEnum.NewStaff} />,
<TestComponent canViewNewStaffCohorts={false} />,
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const NsScenarioGoalPage: React.FC = () => {
<title>{`${appName} | ${t('New Staff Goal Calculator')}`}</title>
</Head>
{scenarioGoalId ? (
<UserTypeAccess requireUserGroups={RequiredUserGroupEnum.MpdGoalCalc}>
<UserTypeAccess
requireUserGroups={RequiredUserGroupEnum.NewStaffCohorts}
>
<GoalSettingsView
scenarioGoalId={scenarioGoalId}
returnUrl={mpdGoalAdminUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { NewStaffGoalCalculationQuery } from 'src/components/HrTools/NsGoalCalcu
import { GetUserQuery } from 'src/components/User/GetUser.generated';
import {
NewStaffQuestionnaireMaritalStatusEnum,
UsStaffGroupEnum,
UserTypeEnum,
} from 'src/graphql/types.generated';
import { GoalCalculatorConstantsQuery } from 'src/hooks/goalCalculatorConstants.generated';
Expand All @@ -32,14 +31,14 @@ const push = jest.fn();
const mutationSpy = jest.fn();

interface TestComponentProps {
/** Senior Staff is the group the MPD goal tools are open to. */
usStaffGroup?: UsStaffGroupEnum;
/** The MPD Goals team and MPD coordinators are the only ones let in. */
canViewNewStaffCohorts?: boolean;
/** Empty stands in for a router that has not resolved the path yet. */
staffAccountListId?: string;
}

const TestComponent: React.FC<TestComponentProps> = ({
usStaffGroup = UsStaffGroupEnum.SeniorStaff,
canViewNewStaffCohorts = true,
staffAccountListId = 'staff-account-list-1',
}) => (
<TestRouter
Expand All @@ -62,7 +61,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
GetUser: {
user: {
userType: UserTypeEnum.UsStaff,
usStaffGroup,
canViewNewStaffCohorts,
staffAccountId: 'staff-account-1',
},
},
Expand Down Expand Up @@ -140,9 +139,9 @@ describe('Staff Details page', () => {
expect(queryByRole('navigation')).not.toBeInTheDocument();
});

it("denies a user outside the admin table's group", async () => {
it('denies a user without goals-team or coordinator access', async () => {
const { findByRole } = render(
<TestComponent usStaffGroup={UsStaffGroupEnum.NewStaff} />,
<TestComponent canViewNewStaffCohorts={false} />,
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const NsStaffDetailsPage: React.FC = () => {
)}`}</title>
</Head>
{staffAccountListId ? (
<UserTypeAccess requireUserGroups={RequiredUserGroupEnum.MpdGoalCalc}>
<UserTypeAccess
requireUserGroups={RequiredUserGroupEnum.NewStaffCohorts}
>
<GoalSettingsView
accountListId={staffAccountListId}
returnUrl={mpdGoalAdminUrl(
Expand Down
29 changes: 29 additions & 0 deletions src/components/Shared/UserTypeAccess/UserTypeAccess.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface TestComponentProps {
spouseUsStaffGroup?: UsStaffGroupEnum;
staffAccountId?: string | null;
supervisesStaff?: boolean;
canViewNewStaffCohorts?: boolean;
requireUserGroups?: RequiredUserGroupEnum;
}

Expand All @@ -30,6 +31,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
spouseUsStaffGroup = UsStaffGroupEnum.PartTimeFieldStaff,
staffAccountId = id,
supervisesStaff = true,
canViewNewStaffCohorts = true,
requireUserGroups,
}) => (
<ThemeProvider theme={theme}>
Expand All @@ -45,6 +47,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
spouseUsStaffGroup,
staffAccountId,
supervisesStaff,
canViewNewStaffCohorts,
},
},
}}
Expand Down Expand Up @@ -218,6 +221,32 @@ describe('UserTypeAccess', () => {
expect(await findByText('Test Content')).toBeInTheDocument();
});

it('should render LimitedAccess when the user may not open the admin table', async () => {
const { findByRole } = render(
<TestComponent
requireUserGroups={RequiredUserGroupEnum.NewStaffCohorts}
canViewNewStaffCohorts={false}
/>,
);

expect(
await findByRole('heading', {
name: 'Access to this feature is limited.',
}),
).toBeInTheDocument();
});

it('should render child component for the goals team and coordinators, whatever their group', async () => {
const { findByText } = render(
<TestComponent
requireUserGroups={RequiredUserGroupEnum.NewStaffCohorts}
canViewNewStaffCohorts
usStaffGroup={UsStaffGroupEnum.NewStaff}
/>,
);
expect(await findByText('Test Content')).toBeInTheDocument();
});

it('should render LimitedAccess when staff account is required but not present', async () => {
const { findByRole, getByText } = render(
<TestComponent requireStaffAccount staffAccountId={null} />,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Shared/UserTypeAccess/UserTypeAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum RequiredUserGroupEnum {
NsGoalCalc = 'nsGoalCalc',
PdsGoalCalc = 'pdsGoalCalc',
MpdSupervisor = 'mpdSupervisor',
NewStaffCohorts = 'newStaffCohorts',
}

export const isUsStaffLike = (user?: UserTypeEnum) =>
Expand Down Expand Up @@ -42,6 +43,7 @@ export const UserTypeAccess: React.FC<UserTypeAccessProps> = ({
inNsGoalCalcIneligibleGroup,
inPdsGoalCalcIneligibleGroup,
inMpdSupervisorIneligibleGroup,
canViewNewStaffCohorts,
userType,
hasNoStaffAccount,
userLoading,
Expand All @@ -57,6 +59,7 @@ export const UserTypeAccess: React.FC<UserTypeAccessProps> = ({
[RequiredUserGroupEnum.NsGoalCalc]: inNsGoalCalcIneligibleGroup,
[RequiredUserGroupEnum.PdsGoalCalc]: inPdsGoalCalcIneligibleGroup,
[RequiredUserGroupEnum.MpdSupervisor]: inMpdSupervisorIneligibleGroup,
[RequiredUserGroupEnum.NewStaffCohorts]: !canViewNewStaffCohorts,
};

const meetsRequiredUserType =
Expand Down
1 change: 1 addition & 0 deletions src/components/User/GetUser.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ query GetUser {
locale: localeDisplay
}
staffAccountId
canViewNewStaffCohorts
primaryDesignation
userType
usStaffGroup
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/NewStaffQuestionnaireStatus.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query NewStaffQuestionnaireStatus($accountListId: ID!) {
newStaffQuestionnaire(accountListId: $accountListId) {
id
completed
}
}
Loading
Loading