Skip to content

Commit 94097b5

Browse files
[PRME-185] Fix nav links on go virus page and complete page (#744)
1 parent 0f133f1 commit 94097b5

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

app/src/components/blocks/_documentUpload/documentUploadInfectedStage/DocumentUploadInfectedStage.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('DocumentUploadInfectedStage', () => {
1919
'One or more of your files has a virus.',
2020
"To keep patient information safe and our systems secure, we've stopped the upload.",
2121
'Contact your local IT support desk for help.',
22-
'Go back to choose Lloyd George files to upload',
22+
'Go to home',
2323
];
2424

2525
render(
@@ -35,7 +35,7 @@ describe('DocumentUploadInfectedStage', () => {
3535

3636
expect(
3737
screen.getByRole('button', {
38-
name: 'Go back to choose Lloyd George files to upload',
38+
name: 'Go to home',
3939
}),
4040
).toBeInTheDocument();
4141
});
@@ -54,21 +54,21 @@ describe('DocumentUploadInfectedStage', () => {
5454
});
5555

5656
describe('Navigation', () => {
57-
it('navigates to Lloyd George upload page when button is clicked', async () => {
57+
it('navigates to home page when button is clicked', async () => {
5858
render(
5959
<MemoryRouter>
6060
<DocumentUploadInfectedStage />
6161
</MemoryRouter>,
6262
);
6363

64-
const backButton = screen.getByRole('button', {
65-
name: 'Go back to choose Lloyd George files to upload',
64+
const homeButton = screen.getByRole('button', {
65+
name: 'Go to home',
6666
});
67-
expect(backButton).toBeInTheDocument();
67+
expect(homeButton).toBeInTheDocument();
6868

69-
await userEvent.click(backButton);
69+
await userEvent.click(homeButton);
7070

71-
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.DOCUMENT_UPLOAD, {
71+
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.HOME, {
7272
replace: true,
7373
});
7474
});

app/src/components/blocks/_documentUpload/documentUploadInfectedStage/DocumentUploadInfectedStage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ function DocumentUploadInfectedStage() {
2424
className="govuk-link"
2525
onClick={(e) => {
2626
e.preventDefault();
27-
navigate(routes.DOCUMENT_UPLOAD, { replace: true });
27+
navigate(routes.HOME, { replace: true });
2828
}}
2929
>
30-
Go back to choose Lloyd George files to upload
30+
Go to home
3131
</button>
3232
</p>
3333
</>

app/src/pages/documentUploadPage/DocumentUploadPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function DocumentUploadPage() {
4747
const baseHeaders = useBaseAPIHeaders();
4848
const [documents, setDocuments] = useState<Array<UploadDocument>>([]);
4949
const [uploadSession, setUploadSession] = useState<UploadSession | null>(null);
50+
const completeRef = useRef(false);
5051
const virusReference = useRef(false);
5152
const navigate = useNavigate();
5253
const [intervalTimer, setIntervalTimer] = useState(0);
@@ -71,12 +72,14 @@ function DocumentUploadPage() {
7172
documents.every((d) => d.state === DOCUMENT_UPLOAD_STATE.SUCCEEDED);
7273

7374
if (hasVirus && !virusReference.current) {
75+
virusReference.current = true;
7476
window.clearInterval(intervalTimer);
7577
navigate(routeChildren.DOCUMENT_UPLOAD_INFECTED);
7678
} else if (docWithError) {
7779
const errorParams = docWithError.error ? errorCodeToParams(docWithError.error) : '';
7880
navigate(routes.SERVER_ERROR + errorParams);
79-
} else if (allFinished) {
81+
} else if (allFinished && !completeRef.current) {
82+
completeRef.current = true;
8083
window.clearInterval(intervalTimer);
8184
navigate(routeChildren.DOCUMENT_UPLOAD_COMPLETED);
8285
}

0 commit comments

Comments
 (0)