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 @@ -10,6 +10,8 @@ import downloadReport from '../../../../helpers/requests/downloadReport';
import { beforeEach, describe, expect, it, vi, MockedFunction, Mock } from 'vitest';

const mockDownloadReport = downloadReport as MockedFunction<typeof downloadReport>;
const mockUseConfig = vi.fn();


const mockedUseNavigate = vi.fn();
vi.mock('react-router-dom', async () => {
Expand All @@ -27,9 +29,16 @@ vi.mock('../../../../helpers/utils/isLocal', () => ({
isMock: (): boolean => false,
}));

vi.mock('../../../../helpers/hooks/useConfig', () => ({
default: (): unknown => mockUseConfig(),
}));

describe('DownloadReportSelectStage', () => {
beforeEach(() => {
import.meta.env.VITE_ENVIRONMENT = 'vitest';
mockUseConfig.mockReturnValue({
featureFlags: {},
});
});

describe('Rendering', () => {
Expand Down Expand Up @@ -107,4 +116,24 @@ describe('DownloadReportSelectStage', () => {
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.HOME);
});
});

it ('should navigate to admin hub, upload version 3 enabled', async () => {
mockUseConfig.mockReturnValue({
featureFlags: { uploadDocumentIteration3Enabled: true },
});

const report = getReportByType(REPORT_TYPE.ODS_PATIENT_SUMMARY);
render(<DownloadReportSelectStage report={report!} />);

let backLink: Element;
backLink = screen.getByTestId('return-to-home-button');

expect(backLink).toHaveTextContent('Go back');

await userEvent.click(backLink);

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.ADMIN_ROUTE);
})
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BackLink, Button } from 'nhsuk-react-components';
import downloadReport from '../../../../helpers/requests/downloadReport';
import useBaseAPIUrl from '../../../../helpers/hooks/useBaseAPIUrl';
import useBaseAPIHeaders from '../../../../helpers/hooks/useBaseAPIHeaders';
import useConfig from '../../../../helpers/hooks/useConfig';
import { AxiosError } from 'axios';
import { isMock } from '../../../../helpers/utils/isLocal';
import { JSX, ReactNode, useRef } from 'react';
Expand All @@ -19,6 +20,7 @@ type Props = {
const DownloadReportSelectStage = (props: Props): JSX.Element => {
const baseUrl = useBaseAPIUrl();
const baseHeaders = useBaseAPIHeaders();
const config = useConfig();
const navigate = useNavigate();
const [downloading, setDownloading] = React.useState(false);
const [downloadError, setDownloadError] = React.useState<ReactNode>(null);
Expand All @@ -28,6 +30,7 @@ const DownloadReportSelectStage = (props: Props): JSX.Element => {
navigate(`${routeChildren.REPORT_DOWNLOAD_COMPLETE}?reportType=${props.report.reportType}`);
};

const uploadV3Enabled: boolean = !!config.featureFlags.uploadDocumentIteration3Enabled;
const noDataContent = (): JSX.Element => {
return (
<>
Expand Down Expand Up @@ -131,11 +134,11 @@ const DownloadReportSelectStage = (props: Props): JSX.Element => {
asElement="a"
href='#'
onClick={(): void => {
navigate(routes.HOME)
uploadV3Enabled ? navigate(routes.ADMIN_ROUTE) : navigate(routes.HOME);
}}
className="mb-5"
>
Go to home
{uploadV3Enabled ? 'Go back' : 'Go to home'}
</BackLink>
{downloadError && (
<NotificationBanner
Expand Down
22 changes: 22 additions & 0 deletions app/src/pages/adminPage/AdminPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ describe('AdminPage', (): void => {
),
).toBeInTheDocument();
});

it('renders the Download a report card', (): void => {
render(<AdminPage />);
const reportLink = screen.getByTestId('download-report-btn');
expect(reportLink).toBeInTheDocument();
expect(reportLink).toHaveTextContent('Download a report');
});

it('renders the Download a report card with correct href', (): void => {
render(<AdminPage />);
const reportLink = screen.getByTestId('download-report-btn');
expect(reportLink).toHaveAttribute('href', '/create-report?reportType=0');
});

it('renders the Download a report card description', (): void => {
render(<AdminPage />);
expect(
screen.getByText(
'This report shows the list of Lloyd George records stored for your organisation.',
),
).toBeInTheDocument();
});
});

describe('Accessibility', (): void => {
Expand Down
26 changes: 23 additions & 3 deletions app/src/pages/adminPage/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Card } from 'nhsuk-react-components';
import { JSX } from 'react';
import useTitle from '../../helpers/hooks/useTitle';
import { ReactComponent as RightCircleIcon } from '../../styles/right-chevron-circle.svg';
import { routeChildren } from '../../types/generic/routes';
import { routeChildren, routes } from '../../types/generic/routes';
import { REPORT_TYPE } from '../../types/generic/reports';
import { useNavigate } from 'react-router-dom';

export const AdminPage = (): JSX.Element => {
Expand All @@ -19,9 +20,9 @@ export const AdminPage = (): JSX.Element => {
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="admin-reviews-btn"
href='#'
href="#"
onClick={(): void => {
navigate(routeChildren.ADMIN_REVIEW)
navigate(routeChildren.ADMIN_REVIEW);
}}
>
Review documents
Expand All @@ -35,6 +36,25 @@ export const AdminPage = (): JSX.Element => {
</Card.Content>
</Card>
</Card.GroupItem>
<Card.GroupItem width="one-half">
<Card clickable cardType="primary">
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="download-report-btn"
href={`${routes.REPORT_DOWNLOAD}?reportType=${REPORT_TYPE.ODS_PATIENT_SUMMARY}`}
>
Download a report
</Card.Link>
</Card.Heading>
<Card.Description>
This report shows the list of Lloyd George records stored for your
organisation.
</Card.Description>
<RightCircleIcon />
</Card.Content>
</Card>
</Card.GroupItem>
</Card.Group>
</>
);
Expand Down
32 changes: 30 additions & 2 deletions app/src/pages/homePage/HomePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ describe('HomePage', () => {
});

describe('Rendering', () => {
it('should render home page with patient search and download report', async () => {
it('should render home page with patient search and download report when uploadDocumentIteration3Enabled is false', async () => {
mockUseConfig.mockReturnValue(
buildConfig(undefined, { uploadDocumentIteration3Enabled: false }),
);
render(<HomePage />);

const searchPatientButton = screen.getByTestId(
'search-patient-btn',
) as HTMLAnchorElement;
Expand Down Expand Up @@ -67,6 +69,32 @@ describe('HomePage', () => {

expect(screen.queryByTestId('admin-console-btn')).not.toBeInTheDocument();
});

it('should render home page with patient search and admin console when uploadDocumentIteration3Enabled is true', async () => {
mockUseConfig.mockReturnValue(
buildConfig(undefined, { uploadDocumentIteration3Enabled: true }),
);
render(<HomePage />);
const searchPatientButton = screen.getByTestId(
'search-patient-btn',
) as HTMLAnchorElement;
const adminConsoleButton = screen.getByTestId('admin-console-btn') as HTMLAnchorElement;
expect(searchPatientButton).toBeInTheDocument();
expect(adminConsoleButton).toBeInTheDocument();
expect(adminConsoleButton).toHaveTextContent('Admin console');
expect(adminConsoleButton).toHaveAttribute('href', '#');
expect(screen.queryByTestId('download-report-btn')).not.toBeInTheDocument();
});

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

render(<HomePage />);

expect(screen.queryByTestId('admin-console-btn')).not.toBeInTheDocument();
});
});

describe('Navigation', () => {
Expand Down
61 changes: 32 additions & 29 deletions app/src/pages/homePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const HomePage = (): React.JSX.Element => {
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="search-patient-btn"
href='#'
href="#"
onClick={(): void => {
navigate(routes.SEARCH_PATIENT)
navigate(routes.SEARCH_PATIENT);
}}
>
View or upload a patient record
Expand All @@ -45,9 +45,9 @@ const HomePage = (): React.JSX.Element => {
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="search-patient-btn"
href='#'
href="#"
onClick={(): void => {
navigate(routes.SEARCH_PATIENT)
navigate(routes.SEARCH_PATIENT);
}}
>
Search for a patient
Expand All @@ -63,16 +63,16 @@ const HomePage = (): React.JSX.Element => {
</Card.Content>
</Card>
</Card.GroupItem>
{config.featureFlags.uploadDocumentIteration3Enabled && (
{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='#'
href="#"
onClick={(): void => {
navigate(routes.ADMIN_ROUTE)
navigate(routes.ADMIN_ROUTE);
}}
>
Admin console
Expand All @@ -85,29 +85,32 @@ const HomePage = (): React.JSX.Element => {
</Card.Content>
</Card>
</Card.GroupItem>
) : (
<Card.GroupItem width="one-half">
<Card clickable cardType="primary">
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="download-report-btn"
href="#"
onClick={(): void => {
navigate(
`${routes.REPORT_DOWNLOAD}?reportType=${REPORT_TYPE.ODS_PATIENT_SUMMARY}`,
);
}}
>
Download a report
</Card.Link>
</Card.Heading>
<Card.Description>
This report shows the list of Lloyd George records stored for
your organisation.
</Card.Description>
<RightCircleIcon />
</Card.Content>
</Card>
</Card.GroupItem>
)}
<Card.GroupItem width="one-half">
<Card clickable cardType="primary">
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link
data-testid="download-report-btn"
href='#'
onClick={(): void => {
navigate(`${routes.REPORT_DOWNLOAD}?reportType=${REPORT_TYPE.ODS_PATIENT_SUMMARY}`)
}}
>
Download a report
</Card.Link>
</Card.Heading>
<Card.Description>
This report shows the list of Lloyd George records stored for your
organisation.
</Card.Description>
<RightCircleIcon />
</Card.Content>
</Card>
</Card.GroupItem>
</Card.Group>
</>
);
Expand Down
Loading