Skip to content

Commit

Permalink
Merge pull request #53 from cabinetoffice/TMI2-192/remove_condition_i…
Browse files Browse the repository at this point in the history
…n_nav_bar_item

TMI2-192:remove conditional rendering of the navBar Item
  • Loading branch information
a-lor-cab authored Aug 21, 2023
2 parents bcc0c5b + cf7cfe3 commit 2125511
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
22 changes: 2 additions & 20 deletions packages/admin/src/pages/super-admin-dashboard/Navigation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import Navigation from './Navigation';
import { Role } from './types';

const roles: Role[] = [
{ name: 'ADMIN', id: '1', description: 'adminRole', label: 'adminLabel' },
{
name: 'TECHNICAL_SUPPORT',
id: '2',
description: 'technicalSupportRole',
label: 'technicalSupportLabel',
},
];

describe('Navigation', () => {
it('renders navigation items correctly when TECHNICAL_SUPPORT role is present in the roles', () => {
const { getByRole } = render(<Navigation roles={roles} />);
const { getByRole } = render(<Navigation />);

expect(getByRole('link', { name: 'Home' })).toBeVisible();
expect(getByRole('link', { name: 'Manage users' })).toBeVisible();
expect(getByRole('link', { name: 'Admin dashboard' })).toBeVisible();
expect(getByRole('link', { name: 'Applicant dashboard' })).toBeVisible();
expect(getByRole('link', { name: 'Manage API Keys' })).toBeVisible();
});

it('does not render "Manage API Keys" link for non-TECHNICAL_SUPPORT roles', () => {
const { queryByText } = render(<Navigation roles={roles.slice(0, 1)} />);

const technicalSupportDashboardLink = queryByText('Manage API Keys');
expect(technicalSupportDashboardLink).toBeNull();
expect(getByRole('link', { name: 'Manage API keys' })).toBeVisible();
});
});
22 changes: 6 additions & 16 deletions packages/admin/src/pages/super-admin-dashboard/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import getConfig from 'next/config';
import Link from 'next/link';
import { Role } from './types';

interface NavigationProps {
roles: Role[];
}

const Navigation = ({ roles }: NavigationProps) => {
const Navigation = () => {
const { publicRuntimeConfig } = getConfig();
const navItems = [
{
Expand All @@ -29,18 +24,13 @@ const Navigation = ({ roles }: NavigationProps) => {
href: publicRuntimeConfig.APPLICANT_DOMAIN + '/dashboard',
title: 'Applicant dashboard',
},
{
pageId: 'technicalDash',
href: publicRuntimeConfig.TECHNICAL_SUPPORT_DOMAIN + '/api-keys',
title: 'Manage API keys',
},
];

const technicalSupportNavItem = {
pageId: 'technicalDash',
href: publicRuntimeConfig.TECHNICAL_SUPPORT_DOMAIN + '/api-keys',
title: 'Manage API Keys',
};

if (roles.find((role) => role.name === 'TECHNICAL_SUPPORT')) {
navItems.push(technicalSupportNavItem);
}

// Build the links in the main navigation && set active states
return (
<nav className="app-navigation govuk-clearfix g2_navigation govuk-width-container">
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/pages/super-admin-dashboard/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { Pagination } from '../../components/pagination/Pagination';
import { getSuperAdminDashboard } from '../../services/SuperAdminService';
import InferProps from '../../types/InferProps';
import PaginationType from '../../types/Pagination';
import { getRedirect } from '../../utils/fetchDataOrGetRedirect';
import { getUserTokenFromCookies } from '../../utils/session';
import Navigation from './Navigation';
import styles from './superadmin-dashboard.module.scss';
import { SuperAdminDashboardFilterData, User } from './types';
import { getRedirect } from '../../utils/fetchDataOrGetRedirect';

export const getServerSideProps = async (
context: GetServerSidePropsContext
Expand Down Expand Up @@ -84,7 +84,7 @@ const SuperAdminDashboard = ({

return (
<>
<Navigation roles={roles} />
<Navigation />

<div className="govuk-grid-row govuk-!-padding-top-7">
<Meta title="Manage Users" />
Expand Down

0 comments on commit 2125511

Please sign in to comment.