Skip to content

Commit f2b5a36

Browse files
swap text on back button, add UT, fix missing return types (#766)
1 parent 883720e commit f2b5a36

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

app/src/components/blocks/_downloadReport/downloadReportCompleteStage/DownloadReportCompleteStage.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ describe('DownloadReportCompleteStage', () => {
2323

2424
expect(screen.getByTestId('home-button')).toBeInTheDocument();
2525
expect(screen.getByTestId('back-to-download-page-button')).toBeInTheDocument();
26+
expect(screen.getByText('Go to home')).toBeInTheDocument();
2627
});
2728
});

app/src/components/blocks/_downloadReport/downloadReportCompleteStage/DownloadReportCompleteStage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { routes } from '../../../../types/generic/routes';
33
import { Button, Card } from 'nhsuk-react-components';
44
import { getFormattedDate } from '../../../../helpers/utils/formatDate';
55
import useTitle from '../../../../helpers/hooks/useTitle';
6+
import { JSX } from 'react';
67

78
type Props = {
89
report: ReportData;
910
};
1011

11-
const DownloadReportCompleteStage = (props: Props) => {
12+
const DownloadReportCompleteStage = (props: Props): JSX.Element => {
1213
useTitle({ pageTitle: 'Download complete' });
1314
return (
1415
<div className="report_download-complete">
@@ -37,7 +38,7 @@ const DownloadReportCompleteStage = (props: Props) => {
3738
</p>
3839

3940
<Button href={routes.HOME} className="mr-6" data-testid="home-button">
40-
Return to Home
41+
Go to home
4142
</Button>
4243
<Button
4344
secondary

app/src/components/blocks/_downloadReport/downloadReportSelectStage/DownloadReportSelectStage.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { render, screen, waitFor } from '@testing-library/react';
2-
import { act } from 'react';
2+
import { act, JSX } from 'react';
33
import DownloadReportSelectStage from './DownloadReportSelectStage';
44
import { getReportByType, REPORT_TYPE } from '../../../../types/generic/reports';
55
import { LinkProps } from 'react-router-dom';
66
import userEvent from '@testing-library/user-event';
77
import React from 'react';
88
import { routes } from '../../../../types/generic/routes';
99
import downloadReport from '../../../../helpers/requests/downloadReport';
10-
import { beforeEach, describe, expect, it, vi, MockedFunction } from 'vitest';
10+
import { beforeEach, describe, expect, it, vi, MockedFunction, Mock } from 'vitest';
1111

1212
const mockDownloadReport = downloadReport as MockedFunction<typeof downloadReport>;
1313

@@ -16,15 +16,15 @@ vi.mock('react-router-dom', async () => {
1616
const actual = await vi.importActual('react-router-dom');
1717
return {
1818
...actual,
19-
Link: (props: LinkProps) => <a {...props} role="link" />,
20-
useNavigate: () => mockedUseNavigate,
19+
Link: (props: LinkProps): JSX.Element => <a {...props} role="link" />,
20+
useNavigate: (): Mock => mockedUseNavigate,
2121
};
2222
});
2323
vi.mock('../../../../helpers/hooks/useBaseAPIUrl');
2424
vi.mock('../../../../helpers/hooks/useBaseAPIHeaders');
2525
vi.mock('../../../../helpers/requests/downloadReport');
2626
vi.mock('../../../../helpers/utils/isLocal', () => ({
27-
isMock: () => false,
27+
isMock: (): boolean => false,
2828
}));
2929

3030
describe('DownloadReportSelectStage', () => {
@@ -47,6 +47,7 @@ describe('DownloadReportSelectStage', () => {
4747
).toBeInTheDocument();
4848
});
4949
expect(screen.queryByTestId('error-notification-banner')).not.toBeInTheDocument();
50+
expect(screen.getByText('Go to home')).toBeInTheDocument();
5051
});
5152

5253
it('should render error notification when download fails', async () => {

app/src/components/blocks/_downloadReport/downloadReportSelectStage/DownloadReportSelectStage.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import useBaseAPIUrl from '../../../../helpers/hooks/useBaseAPIUrl';
77
import useBaseAPIHeaders from '../../../../helpers/hooks/useBaseAPIHeaders';
88
import { AxiosError } from 'axios';
99
import { isMock } from '../../../../helpers/utils/isLocal';
10-
import { ReactNode, useRef } from 'react';
10+
import { JSX, ReactNode, useRef } from 'react';
1111
import NotificationBanner from '../../../layout/notificationBanner/NotificationBanner';
1212
import SpinnerButton from '../../../generic/spinnerButton/SpinnerButton';
1313
import React from 'react';
@@ -16,19 +16,19 @@ type Props = {
1616
report: ReportData;
1717
};
1818

19-
const DownloadReportSelectStage = (props: Props) => {
19+
const DownloadReportSelectStage = (props: Props): JSX.Element => {
2020
const baseUrl = useBaseAPIUrl();
2121
const baseHeaders = useBaseAPIHeaders();
2222
const navigate = useNavigate();
2323
const [downloading, setDownloading] = React.useState(false);
2424
const [downloadError, setDownloadError] = React.useState<ReactNode>(null);
2525
const scrollToRef = useRef<HTMLDivElement>(null);
2626

27-
const handleSuccess = () => {
27+
const handleSuccess = (): void => {
2828
navigate(`${routeChildren.REPORT_DOWNLOAD_COMPLETE}?reportType=${props.report.reportType}`);
2929
};
3030

31-
const noDataContent = () => {
31+
const noDataContent = (): JSX.Element => {
3232
return (
3333
<>
3434
<h3>Report could not be created</h3>
@@ -50,7 +50,7 @@ const DownloadReportSelectStage = (props: Props) => {
5050
);
5151
};
5252

53-
const serverErrorContent = () => {
53+
const serverErrorContent = (): JSX.Element => {
5454
return (
5555
<>
5656
<h3>Download failed</h3>
@@ -70,7 +70,7 @@ const DownloadReportSelectStage = (props: Props) => {
7070
);
7171
};
7272

73-
const handleError = (errorCode: number) => {
73+
const handleError = (errorCode: number): void => {
7474
if (errorCode === 403) {
7575
navigate(routes.SESSION_EXPIRED);
7676
return;
@@ -81,7 +81,7 @@ const DownloadReportSelectStage = (props: Props) => {
8181
scrollToRef.current?.scrollIntoView();
8282
};
8383

84-
const handleDownload = async (fileType: string) => {
84+
const handleDownload = async (fileType: string): Promise<void> => {
8585
setDownloading(true);
8686

8787
try {
@@ -100,7 +100,7 @@ const DownloadReportSelectStage = (props: Props) => {
100100
setDownloading(false);
101101
};
102102

103-
const DownloadLinks = (fileTypes: FileTypeData[]) => {
103+
const DownloadLinks = (fileTypes: FileTypeData[]): JSX.Element | JSX.Element[] => {
104104
if (downloading) {
105105
return (
106106
<SpinnerButton id="download-spinner" status="Downloading report" disabled={true} />
@@ -113,7 +113,7 @@ const DownloadReportSelectStage = (props: Props) => {
113113
data-testid={`download-${fileType.extension}-button`}
114114
secondary
115115
className="mb-5"
116-
onClick={async () => {
116+
onClick={async (): Promise<void> => {
117117
handleDownload(fileType.extension);
118118
}}
119119
key={fileType.extension}
@@ -132,7 +132,7 @@ const DownloadReportSelectStage = (props: Props) => {
132132
href={routes.HOME}
133133
className="mb-5"
134134
>
135-
Return to Home
135+
Go to home
136136
</BackLink>
137137
{downloadError && (
138138
<NotificationBanner

app/src/pages/patientSearchPage/PatientSearchPage.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('PatientSearchPage', () => {
5757
screen.getByText('A 10-digit number, for example, 485 777 3456'),
5858
).toBeInTheDocument();
5959
expect(screen.getByRole('button', { name: 'Search' })).toBeInTheDocument();
60+
expect(screen.getByText('Go to home')).toBeInTheDocument();
6061
},
6162
);
6263
it.skip("displays a loading spinner when the patients details are being requested when user role is '%s'", async (role) => {

app/src/pages/patientSearchPage/PatientSearchPage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { JSX, useState } from 'react';
22
import { routes } from '../../types/generic/routes';
33
import { FieldValues, useForm } from 'react-hook-form';
44
import ErrorBox from '../../components/layout/errorBox/ErrorBox';
@@ -26,7 +26,7 @@ import { REPOSITORY_ROLE } from '../../types/generic/authRole';
2626

2727
export const incorrectFormatMessage = "Enter patient's 10 digit NHS number";
2828

29-
function PatientSearchPage() {
29+
function PatientSearchPage(): JSX.Element {
3030
const [, setPatientDetails] = usePatientDetailsContext();
3131
const [submissionState, setSubmissionState] = useState<SEARCH_STATES>(SEARCH_STATES.IDLE);
3232
const [statusCode, setStatusCode] = useState<null | number>(null);
@@ -49,7 +49,7 @@ function PatientSearchPage() {
4949
const isError = (statusCode && statusCode >= 500) || !inputError;
5050
const baseUrl = useBaseAPIUrl();
5151
const baseHeaders = useBaseAPIHeaders();
52-
const handleSuccess = (patientDetails: PatientDetails) => {
52+
const handleSuccess = (patientDetails: PatientDetails): void => {
5353
setPatientDetails(patientDetails);
5454
setSubmissionState(SEARCH_STATES.SUCCEEDED);
5555
navigate(routes.VERIFY_PATIENT);
@@ -59,12 +59,12 @@ function PatientSearchPage() {
5959
const pageTitle = 'Search for a patient';
6060
useTitle({ pageTitle: pageTitle });
6161

62-
const setFailedSubmitState = (statusCode: number | null) => {
62+
const setFailedSubmitState = (statusCode: number | null): void => {
6363
setStatusCode(statusCode);
6464
setSubmissionState(SEARCH_STATES.FAILED);
6565
};
6666

67-
const handleSearch = async (data: FieldValues) => {
67+
const handleSearch = async (data: FieldValues): Promise<void> => {
6868
setSubmissionState(SEARCH_STATES.SEARCHING);
6969
setInputError(null);
7070
setStatusCode(null);
@@ -117,7 +117,7 @@ function PatientSearchPage() {
117117
setFailedSubmitState(error.response?.status ?? null);
118118
}
119119
};
120-
const handleError = (fields: FieldValues) => {
120+
const handleError = (fields: FieldValues): void => {
121121
const errorMessages = Object.entries(fields).map(
122122
([k, v]: [string, { message: string }]) => v.message,
123123
);
@@ -126,7 +126,7 @@ function PatientSearchPage() {
126126
return (
127127
<>
128128
<BackLink asElement="a" href={routes.HOME}>
129-
Return to Home
129+
Go to home
130130
</BackLink>
131131
{(submissionState === SEARCH_STATES.FAILED ||
132132
inputError === incorrectFormatMessage) && (

0 commit comments

Comments
 (0)