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
46 changes: 46 additions & 0 deletions app/src/pages/adminPage/AdminPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { render, screen } from '@testing-library/react';
import { AdminPage } from './AdminPage';
import { runAxeTest } from '../../helpers/test/axeTestHelper';
import { describe, expect, it, vi } from 'vitest';
import { routeChildren } from '../../types/generic/routes';

vi.mock('../../../helpers/hooks/useTitle');

describe('AdminPage', (): void => {
describe('Rendering', (): void => {
it('renders the admin console heading', (): void => {
render(<AdminPage />);
expect(screen.getByRole('heading', { name: 'Admin console' })).toBeInTheDocument();
});

it('renders the Reviews card', (): void => {
render(<AdminPage />);
const reviewsLink = screen.getByTestId('admin-reviews-btn');
expect(reviewsLink).toBeInTheDocument();
expect(reviewsLink).toHaveTextContent('Reviews');
});

it('renders the Reviews card with correct href', (): void => {
render(<AdminPage />);
const reviewsLink = screen.getByTestId('admin-reviews-btn');
expect(reviewsLink).toHaveAttribute('href', routeChildren.ADMIN_REVIEW);
});

it('renders the Reviews card description', (): void => {
render(<AdminPage />);
expect(
screen.getByText(
'Review documents from practice to practice transfers and rejections from bulk transfer into this service.',
),
).toBeInTheDocument();
});
});

describe('Accessibility', (): void => {
it('passes accessibility checks', async (): Promise<void> => {
render(<AdminPage />);
const results = await runAxeTest(document.body);
expect(results).toHaveNoViolations();
});
});
});
37 changes: 37 additions & 0 deletions app/src/pages/adminPage/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Card } from 'nhsuk-react-components';
import { JSX } from 'react';
import useTitle from '../../helpers/hooks/useTitle';
import { routeChildren } from '../../types/generic/routes';
import { ReactComponent as RightCircleIcon } from '../../styles/right-chevron-circle.svg';

export const AdminPage = (): JSX.Element => {
useTitle({ pageTitle: 'Admin console' });

return (
<>
<h1>Admin console</h1>
<Card.Group>
<Card.GroupItem width="one-half">
{/* Reviews */}
<Card clickable cardType="primary">
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="admin-reviews-btn"
href={routeChildren.ADMIN_REVIEW}
>
Reviews
</Card.Link>
</Card.Heading>
<Card.Description>
Review documents from practice to practice transfers and rejections
from bulk transfer into this service.
</Card.Description>
<RightCircleIcon />
</Card.Content>
</Card>
</Card.GroupItem>
</Card.Group>
</>
);
};
14 changes: 14 additions & 0 deletions app/src/pages/adminRoutesPage/AdminRoutesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { JSX } from 'react';
import { Routes, Route } from 'react-router';
import { AdminPage } from '../adminPage/AdminPage';
import { routeChildren } from '../../types/generic/routes';
import { getLastURLPath } from '../../helpers/utils/urlManipulations';

export const AdminRoutesPage = (): JSX.Element => {
return (
<Routes>
<Route path={getLastURLPath(routeChildren.ADMIN_REVIEW)} element={<></>} />
<Route path="*" element={<AdminPage />} />
</Routes>
);
};
54 changes: 29 additions & 25 deletions app/src/pages/homePage/HomePage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { render, screen } from '@testing-library/react';
import HomePage from './HomePage';
import useRole from '../../helpers/hooks/useRole';
import { REPOSITORY_ROLE } from '../../types/generic/authRole';
import { buildConfig } from '../../helpers/test/testBuilders';
import useConfig from '../../helpers/hooks/useConfig';
import { routes } from '../../types/generic/routes';
import { afterEach, beforeEach, describe, expect, it, vi, Mock } from 'vitest';

const mockedUseNavigate = vi.fn();
Expand All @@ -15,9 +14,7 @@ vi.mock('react-router-dom', async () => {
};
});

vi.mock('../../helpers/hooks/useRole');
vi.mock('../../helpers/hooks/useConfig');
const mockUseRole = useRole as Mock;
const mockUseConfig = useConfig as Mock;

describe('HomePage', () => {
Expand All @@ -27,33 +24,40 @@ describe('HomePage', () => {
afterEach(() => {
vi.clearAllMocks();
});
const gpRoles = [REPOSITORY_ROLE.GP_ADMIN, REPOSITORY_ROLE.GP_CLINICAL];

const validateHomePageRendered = () => {
render(<HomePage />);
describe('Rendering', () => {
it('should render home page with patient search and download report', async () => {
render(<HomePage />);

const searchPatientButton = screen.getByTestId('search-patient-btn') as HTMLAnchorElement;
const downloadReportButton = screen.getByTestId('download-report-btn') as HTMLAnchorElement;
expect(searchPatientButton).toBeInTheDocument();
expect(downloadReportButton).toBeInTheDocument();
};
const searchPatientButton = screen.getByTestId('search-patient-btn') as HTMLAnchorElement;
const downloadReportButton = screen.getByTestId('download-report-btn') as HTMLAnchorElement;
expect(searchPatientButton).toBeInTheDocument();
expect(downloadReportButton).toBeInTheDocument();
});
});

describe('Rendering for GP roles', () => {
it.each(gpRoles)(
'[%s] render home page with patient search and download report',
async (role) => {
mockUseRole.mockReturnValue(role);
describe('Admin Console button', () => {
it('renders admin console button when feature flag is enabled', () => {
mockUseConfig.mockReturnValue(
buildConfig(undefined, { uploadDocumentIteration3Enabled: true }),
);

validateHomePageRendered();
},
);
});
render(<HomePage />);

describe('PCSE Rendering', () => {
it('should render home page with patient search and download report', async () => {
mockUseRole.mockReturnValue(REPOSITORY_ROLE.PCSE);
const adminConsoleButton = screen.getByTestId('admin-console-btn') as HTMLAnchorElement;
expect(adminConsoleButton).toBeInTheDocument();
expect(adminConsoleButton).toHaveTextContent('Admin console');
expect(adminConsoleButton).toHaveAttribute('href', routes.ADMIN_ROUTE);
});

it('does not render admin console button when feature flag is disabled', () => {
mockUseConfig.mockReturnValue(
buildConfig(undefined, { uploadDocumentIteration3Enabled: false }),
);

render(<HomePage />);

validateHomePageRendered();
expect(screen.queryByTestId('admin-console-btn')).not.toBeInTheDocument();
});
});
});
20 changes: 20 additions & 0 deletions app/src/pages/homePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ const HomePage = (): React.JSX.Element => {
</Card.Content>
</Card>
</Card.GroupItem>
{config.featureFlags.uploadDocumentIteration3Enabled &&
<Card.GroupItem width="one-half">
<Card clickable cardType="primary">
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="admin-console-btn"
href={routes.ADMIN_ROUTE}
>
Admin console
</Card.Link>
</Card.Heading>
<Card.Description>
Review records and actions for incoming patients
</Card.Description>
<RightCircleIcon />
</Card.Content>
</Card>
</Card.GroupItem>
}
</Card.Group>
</>
);
Expand Down
15 changes: 15 additions & 0 deletions app/src/router/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import NonAuthGuard from './guards/notAuthGuard/NonAuthGuard';
import PatientAccessAuditPage from '../pages/patientAccessAuditPage/PatientAccessAuditPage';
import MockLoginPage from '../pages/mockLoginPage/MockLoginPage';
import DocumentUploadPage from '../pages/documentUploadPage/DocumentUploadPage';
import { AdminRoutesPage } from '../pages/adminRoutesPage/AdminRoutesPage';

const {
START,
Expand Down Expand Up @@ -55,6 +56,8 @@ const {
MOCK_LOGIN,
DOCUMENT_UPLOAD,
DOCUMENT_UPLOAD_WILDCARD,
ADMIN_ROUTE,
ADMIN_ROUTE_WILDCARD,
} = routes;

type Routes = {
Expand Down Expand Up @@ -146,6 +149,10 @@ export const childRoutes = [
route: routeChildren.DOCUMENT_UPLOAD_FILE_ERRORS,
parent: DOCUMENT_UPLOAD,
},
{
route: routeChildren.ADMIN_REVIEW,
parent: ADMIN_ROUTE,
},
];

export const routeMap: Routes = {
Expand Down Expand Up @@ -227,6 +234,14 @@ export const routeMap: Routes = {
page: <ReportDownloadPage />,
type: ROUTE_TYPE.PRIVATE,
},
[ADMIN_ROUTE]: {
page: <AdminRoutesPage />,
type: ROUTE_TYPE.PRIVATE,
},
[ADMIN_ROUTE_WILDCARD]: {
page: <AdminRoutesPage />,
type: ROUTE_TYPE.PRIVATE,
},

// App guard routes
[VERIFY_PATIENT]: {
Expand Down
5 changes: 5 additions & 0 deletions app/src/types/generic/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export enum routes {
DOCUMENT_UPLOAD_WILDCARD = '/patient/document-upload/*',

MOCK_LOGIN = 'Auth/MockLogin',

ADMIN_ROUTE = '/admin',
ADMIN_ROUTE_WILDCARD = '/admin/*',
}

export enum routeChildren {
Expand All @@ -55,6 +58,8 @@ export enum routeChildren {
DOCUMENT_DELETE = '/patient/documents/delete',
DOCUMENT_DELETE_CONFIRMATION = '/patient/documents/delete/confirmation',
DOCUMENT_DELETE_COMPLETE = '/patient/documents/delete/complete',

ADMIN_REVIEW = '/admin/reviews',
}

export enum ROUTE_TYPE {
Expand Down
Loading