Skip to content

Commit e21d3a6

Browse files
authored
Updated pdf message message. (#745)
Updated typing definitions on relvant pages. Sorted the imports. (New imported dependancies only JSX for type definitions and RenderResult for the test file again for type definition.)
1 parent 94097b5 commit e21d3a6

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

app/src/components/blocks/_documentUpload/documentSelectStage/DocumentSelectStage.test.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
// need to use happy-dom for this test file as jsdom doesn't support DOMMatrix https://github.com/jsdom/jsdom/issues/2647
22
// @vitest-environment happy-dom
3-
import { render, waitFor, screen, fireEvent } from '@testing-library/react';
4-
import { DOCUMENT_TYPE, UploadDocument } from '../../../../types/pages/UploadDocumentsPage/types';
5-
import DocumentSelectStage, { Props } from './DocumentSelectStage';
6-
import { buildLgFile } from '../../../../helpers/test/testBuilders';
3+
import { fireEvent, render, RenderResult, screen, waitFor } from '@testing-library/react';
74
import userEvent from '@testing-library/user-event';
8-
import { useState } from 'react';
5+
import { createMemoryHistory, MemoryHistory } from 'history';
6+
import { getDocument } from 'pdfjs-dist';
7+
import { JSX, useState } from 'react';
98
import * as ReactRouter from 'react-router-dom';
10-
import { MemoryHistory, createMemoryHistory } from 'history';
11-
import { routeChildren, routes } from '../../../../types/generic/routes';
12-
import { buildPatientDetails } from '../../../../helpers/test/testBuilders';
139
import usePatient from '../../../../helpers/hooks/usePatient';
14-
import { formatNhsNumber } from '../../../../helpers/utils/formatNhsNumber';
15-
import { getFormattedDate } from '../../../../helpers/utils/formatDate';
16-
import { getDocument } from 'pdfjs-dist';
10+
import { buildLgFile, buildPatientDetails } from '../../../../helpers/test/testBuilders';
1711
import {
1812
fileUploadErrorMessages,
1913
PDF_PARSING_ERROR_TYPE,
2014
} from '../../../../helpers/utils/fileUploadErrorMessages';
15+
import { getFormattedDate } from '../../../../helpers/utils/formatDate';
16+
import { formatNhsNumber } from '../../../../helpers/utils/formatNhsNumber';
17+
import { routeChildren, routes } from '../../../../types/generic/routes';
18+
import { DOCUMENT_TYPE, UploadDocument } from '../../../../types/pages/UploadDocumentsPage/types';
19+
import DocumentSelectStage, { Props } from './DocumentSelectStage';
2120

2221
vi.mock('../../../../helpers/hooks/usePatient');
2322
vi.mock('react-router-dom', async () => {
2423
const actual = await vi.importActual('react-router-dom');
2524
return {
2625
...actual,
27-
Link: (props: ReactRouter.LinkProps) => <a {...props} role="link" />,
28-
useNavigate: () => mockedUseNavigate,
26+
Link: (props: ReactRouter.LinkProps): JSX.Element => <a {...props} role="link" />,
27+
useNavigate: (): typeof mockedUseNavigate => mockedUseNavigate,
2928
};
3029
});
3130
vi.mock('pdfjs-dist');
@@ -256,7 +255,7 @@ describe('DocumentSelectStage', () => {
256255
});
257256
});
258257

259-
const TestApp = (props: Partial<Props>) => {
258+
const TestApp = (props: Partial<Props>): JSX.Element => {
260259
const [documents, setDocuments] = useState<Array<UploadDocument>>([]);
261260

262261
return (
@@ -271,7 +270,7 @@ describe('DocumentSelectStage', () => {
271270
const renderApp = (
272271
history: MemoryHistory,
273272
docType: DOCUMENT_TYPE = DOCUMENT_TYPE.LLOYD_GEORGE,
274-
) => {
273+
): RenderResult => {
275274
return render(
276275
<ReactRouter.Router navigator={history} location={history.location}>
277276
<TestApp documentType={docType} />

app/src/components/blocks/_documentUpload/documentSelectStage/DocumentSelectStage.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { useRef, useState } from 'react';
1+
import { Button, Fieldset, Table, TextInput } from 'nhsuk-react-components';
2+
import { getDocument } from 'pdfjs-dist';
3+
import { JSX, useRef, useState } from 'react';
4+
import { useNavigate } from 'react-router-dom';
5+
import { v4 as uuidv4 } from 'uuid';
6+
import useTitle from '../../../../helpers/hooks/useTitle';
7+
import {
8+
fileUploadErrorMessages,
9+
PDF_PARSING_ERROR_TYPE,
10+
UPLOAD_FILE_ERROR_TYPE,
11+
} from '../../../../helpers/utils/fileUploadErrorMessages';
12+
import formatFileSize from '../../../../helpers/utils/formatFileSize';
13+
import { routeChildren, routes } from '../../../../types/generic/routes';
214
import {
315
DOCUMENT_TYPE,
416
DOCUMENT_UPLOAD_STATE,
@@ -7,30 +19,18 @@ import {
719
UploadDocument,
820
UploadFilesError,
921
} from '../../../../types/pages/UploadDocumentsPage/types';
10-
import { v4 as uuidv4 } from 'uuid';
1122
import BackButton from '../../../generic/backButton/BackButton';
12-
import { useNavigate } from 'react-router-dom';
13-
import { routeChildren, routes } from '../../../../types/generic/routes';
14-
import useTitle from '../../../../helpers/hooks/useTitle';
15-
import { Button, Fieldset, Table, TextInput } from 'nhsuk-react-components';
16-
import formatFileSize from '../../../../helpers/utils/formatFileSize';
1723
import LinkButton from '../../../generic/linkButton/LinkButton';
18-
import { getDocument } from 'pdfjs-dist';
1924
import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/PatientSummary';
2025
import ErrorBox from '../../../layout/errorBox/ErrorBox';
21-
import {
22-
fileUploadErrorMessages,
23-
PDF_PARSING_ERROR_TYPE,
24-
UPLOAD_FILE_ERROR_TYPE,
25-
} from '../../../../helpers/utils/fileUploadErrorMessages';
2626

2727
export type Props = {
2828
setDocuments: SetUploadDocuments;
2929
documents: Array<UploadDocument>;
3030
documentType: DOCUMENT_TYPE;
3131
};
3232

33-
const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) => {
33+
const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props): JSX.Element => {
3434
const fileInputRef = useRef<HTMLInputElement | null>(null);
3535
const [noFilesSelected, setNoFilesSelected] = useState<boolean>(false);
3636
const scrollToRef = useRef<HTMLDivElement>(null);
@@ -168,7 +168,7 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
168168
navigate(routeChildren.DOCUMENT_UPLOAD_SELECT_ORDER);
169169
};
170170

171-
const DocumentRow = (document: UploadDocument, index: number) => {
171+
const DocumentRow = (document: UploadDocument, index: number): JSX.Element => {
172172
return (
173173
<Table.Row key={document.id} id={document.file.name}>
174174
<Table.Cell className={document.error ? 'error-cell' : ''}>
@@ -188,7 +188,7 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
188188
type="button"
189189
aria-label={`Remove ${document.file.name} from selection`}
190190
className="link-button"
191-
onClick={() => {
191+
onClick={(): void => {
192192
onRemove(index);
193193
}}
194194
>
@@ -213,7 +213,7 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
213213

214214
useTitle({ pageTitle: pageTitle() });
215215

216-
const errorDocs = () => {
216+
const errorDocs = (): UploadDocument[] => {
217217
return documents.filter((doc) => doc.error && doc.validated);
218218
};
219219

@@ -296,7 +296,7 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
296296
id="upload-files"
297297
tabIndex={0}
298298
data-testid="dropzone"
299-
onDragOver={(e) => {
299+
onDragOver={(e): void => {
300300
e.preventDefault();
301301
}}
302302
onDrop={onFileDrop}
@@ -312,20 +312,20 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
312312
multiple={true}
313313
hidden
314314
accept={allowedFileTypes()}
315-
onChange={(e: FileInputEvent) => {
315+
onChange={(e: FileInputEvent): void => {
316316
onInput(e);
317317
e.target.value = '';
318318
}}
319319
// @ts-ignore The NHS Component library is outdated and does not allow for any reference other than a blank MutableRefObject
320-
inputRef={(e: HTMLInputElement) => {
320+
inputRef={(e: HTMLInputElement): void => {
321321
fileInputRef.current = e;
322322
}}
323323
/>
324324
<Button
325325
data-testid={`upload-button-input`}
326326
type={'button'}
327327
className={'nhsuk-button nhsuk-button--secondary bottom-margin'}
328-
onClick={() => {
328+
onClick={(): void => {
329329
fileInputRef.current?.click();
330330
}}
331331
aria-labelledby="upload-fieldset-legend"
@@ -365,7 +365,7 @@ const DocumentSelectStage = ({ documents, setDocuments, documentType }: Props) =
365365
type="button"
366366
className="remove-all-button mb-5"
367367
data-testid="remove-all-button"
368-
onClick={() => {
368+
onClick={(): void => {
369369
navigate(routeChildren.DOCUMENT_UPLOAD_REMOVE_ALL);
370370
}}
371371
>

app/src/helpers/utils/fileUploadErrorMessages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export const fileUploadErrorMessages: errorMessageType = {
6767
errorBox: 'The selected file is password protected. Remove password and upload again.',
6868
},
6969
emptyPdf: {
70-
inline: 'The selected file is empty. Remove it to continue with upload.',
71-
errorBox: 'The selected file is empty. Remove it to continue with upload.',
70+
inline: 'The selected file is empty. Check it to continue with upload.',
71+
errorBox: 'The selected file is empty. Check it to continue with upload.',
7272
},
7373
duplicatePositionError: {
7474
inline: 'You have selected the same position number for two or more files',

0 commit comments

Comments
 (0)