Skip to content

Commit a70516c

Browse files
AndyFlintNHSMohammadIqbalAD-NHSoliverbeumkes-nhs
authored
[PRMP-1074] Refreshing browser redirects to search patient page (#476)
* [PRMP-1074] Refreshing browser redirects to search patient page * [PRMP-1074] Cypress test for browser refresh * [PRMP-1074] Removed unused import * [PRMP-1074] - Return to patient search if nhsNumber missing * [PRMP-1074] - Return to patient search if nhsNumber missing when downloading files --------- Co-authored-by: Mohammad Iqbal <mohammad.iqbal27@nhs.net> Co-authored-by: oliverbeumkes-nhs <oliver.beumkes2@nhs.net>
1 parent bc66a60 commit a70516c

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_general_browser_states.cy.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import authPayload from '../../../fixtures/requests/auth/GET_TokenRequest_GP_ADMIN.json';
22
import { Roles } from '../../../support/roles';
3+
import dbItem from '../../../fixtures/dynamo-db-items/active-patient.json';
4+
import searchPatientPayload from '../../../fixtures/requests/GET_SearchPatientLGUpload.json';
35

46
describe('Authentication & Authorisation', () => {
57
const baseUrl = Cypress.config('baseUrl');
@@ -86,4 +88,42 @@ describe('Authentication & Authorisation', () => {
8688
},
8789
);
8890
});
91+
92+
context('Page refresh redirection ', () => {
93+
const workspace = Cypress.env('WORKSPACE');
94+
dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace);
95+
96+
const lloydGeorgeRecordUrl = '/patient/lloyd-george-record';
97+
const verifyUrl = '/patient/verify';
98+
const patientSearchUrl = '/patient/search';
99+
100+
it(
101+
'Refreshing the browser after searching for a patient will return the user to the patient search page',
102+
{ tags: 'regression ', defaultCommandTimeout: 20000 },
103+
() => {
104+
cy.login(Roles.GP_ADMIN);
105+
cy.visit(patientSearchUrl);
106+
107+
cy.intercept('GET', '/SearchPatient*', {
108+
statusCode: 200,
109+
body: searchPatientPayload,
110+
}).as('search');
111+
cy.intercept('POST', '/LloydGeorgeStitch*', {
112+
statusCode: 404,
113+
}).as('stitch');
114+
115+
cy.getByTestId('nhs-number-input').type(searchPatientPayload.nhsNumber);
116+
cy.getByTestId('search-submit-btn').click();
117+
118+
cy.url().should('contain', verifyUrl);
119+
cy.get('#verify-submit').click();
120+
121+
cy.url().should('contain', lloydGeorgeRecordUrl);
122+
123+
cy.reload();
124+
125+
cy.url().should('contain', patientSearchUrl);
126+
},
127+
);
128+
});
89129
});

app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadStage/LloydGeorgeDownloadStage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ function LloydGeorgeDownloadStage({
9595
const onPageLoad = async () => {
9696
progressTimer.stop();
9797
window.clearInterval(intervalTimer);
98+
if (!nhsNumber) {
99+
navigate(routes.SEARCH_PATIENT);
100+
return;
101+
}
98102
try {
99103
const preSignedUrl = await getPresignedUrlForZip({
100104
baseUrl,

app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ function LloydGeorgeSelectDownloadStage({
8585
useEffect(() => {
8686
const onPageLoad = async () => {
8787
setSubmissionSearchState(SEARCH_AND_DOWNLOAD_STATE.SEARCH_PENDING);
88+
if (!nhsNumber) {
89+
navigate(routes.SEARCH_PATIENT);
90+
return;
91+
}
8892
try {
8993
// This check is in place for when we navigate directly to a full download,
9094
// in that instance we do not need to get a list of selectable files as we will download all files

app/src/router/guards/patientGuard/PatientGuard.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ describe('AuthGuard', () => {
1919
afterEach(() => {
2020
jest.clearAllMocks();
2121
});
22-
it('navigates user to unauthorised when no patient is searched', async () => {
22+
it('navigates user to search patient page when no patient details are stored', async () => {
2323
mockedUsePatient.mockReturnValue(null);
2424

2525
renderGuard();
2626

2727
await waitFor(async () => {
28-
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.UNAUTHORISED);
28+
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.SEARCH_PATIENT);
2929
});
3030
});
3131

app/src/router/guards/patientGuard/PatientGuard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function PatientGuard({ children }: Props) {
1212
const navigate = useNavigate();
1313
useEffect(() => {
1414
if (!patient) {
15-
navigate(routes.UNAUTHORISED);
15+
navigate(routes.SEARCH_PATIENT);
1616
}
1717
}, [patient, navigate]);
1818
return <>{children}</>;

0 commit comments

Comments
 (0)