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
37 changes: 37 additions & 0 deletions packages/cpt-ui/__tests__/EpsRoleSelectionPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,43 @@ describe("RoleSelectionPage", () => {
expect(screen.getByText("Admin")).toBeInTheDocument()
})

it("doesnt render the roles without access title or table when no rolesWithoutAccess are present", () => {
mockUseAuth.mockReturnValue({
isSigningIn: false,
selectedRole: {
role_id: "1"
},
rolesWithAccess: [
{
role_id: "2",
role_name: "Pharmacist",
org_code: "ABC",
org_name: "Pharmacy Org"
},
{
role_id: "3",
role_name: "Technician",
org_code: "XYZ",
org_name: "Tech Org"
},
{
role_id: "1",
role_name: "Admin",
org_code: "ZZZ",
org_name: "Same Org"
}
],
rolesWithoutAccess: [],
error: null,
hasSingleRoleAccess: jest.fn().mockReturnValue(false)
})
render(<MemoryRouter>
<RoleSelectionPage contentText={defaultContentText} />
</MemoryRouter>)
expect(screen.queryByText("View your roles without access to the Prescription Tracker.")).not.toBeInTheDocument()
expect(screen.queryByTestId("roles-without-access-table")).not.toBeInTheDocument()
})

it("renders EpsCard components for roles with access", () => {
mockUseAuth.mockReturnValue({
isSigningIn: false,
Expand Down
67 changes: 33 additions & 34 deletions packages/cpt-ui/src/components/EpsRoleSelectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ export default function RoleSelectionPage({
</section>
)}
</Col>

{(auth.rolesWithAccess.length > 0) && (roleComponentProps.rolesWithAccess.length > 0) && (
<Col width="two-thirds">
<div className="section">
Expand Down Expand Up @@ -398,39 +397,39 @@ export default function RoleSelectionPage({
</div>
</Col>
)}

<Col width="two-thirds">
<h3>{rolesWithoutAccessHeader}</h3>
<Details expander>
<Details.Summary>
{roles_without_access_table_title}
</Details.Summary>
<Details.Text>
<Table>
<Table.Head>
<Table.Row>
<Table.Cell>{organisation}</Table.Cell>
<Table.Cell>{role}</Table.Cell>
</Table.Row>
</Table.Head>
<Table.Body>
{roleComponentProps.rolesWithoutAccess.map(
(roleItem: RolesWithoutAccessProps) => (
<Table.Row key={roleItem.uuid}>
<Table.Cell data-testid="change-role-name-cell">
{roleItem.orgName} (ODS: {roleItem.odsCode})
</Table.Cell>
<Table.Cell data-testid="change-role-role-cell">
{roleItem.roleName}
</Table.Cell>
</Table.Row>
)
)}
</Table.Body>
</Table>
</Details.Text>
</Details>
</Col>
{roleComponentProps.rolesWithoutAccess?.length > 0 && (
<Col width="two-thirds">
<h3>{rolesWithoutAccessHeader}</h3>
<Details expander>
<Details.Summary>
{roles_without_access_table_title}
</Details.Summary>
<Details.Text>
<Table>
<Table.Head>
<Table.Row>
<Table.Cell>{organisation}</Table.Cell>
<Table.Cell>{role}</Table.Cell>
</Table.Row>
</Table.Head>
<Table.Body>
{roleComponentProps.rolesWithoutAccess.map(
(roleItem: RolesWithoutAccessProps) => (
<Table.Row key={roleItem.uuid}>
<Table.Cell data-testid="change-role-name-cell">
{roleItem.orgName} (ODS: {roleItem.odsCode})
</Table.Cell>
<Table.Cell data-testid="change-role-role-cell">
{roleItem.roleName}
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
</Details.Text>
</Details>
</Col>
)}
</Row>
</Container>
}
Expand Down
Loading