diff --git a/app/cypress/e2e/0-ndr-core-tests/gp_view_lloyd_george_workflow.cy.js b/app/cypress/e2e/0-ndr-core-tests/gp_view_lloyd_george_workflow.cy.js index f997e38d0..dcb60f786 100644 --- a/app/cypress/e2e/0-ndr-core-tests/gp_view_lloyd_george_workflow.cy.js +++ b/app/cypress/e2e/0-ndr-core-tests/gp_view_lloyd_george_workflow.cy.js @@ -12,8 +12,8 @@ describe('GP View Lloyd George Workflow', () => { statusCode: 200, body: searchPatientPayload, }).as('search'); - cy.get('#nhs-number-input').type(searchPatientPayload.nhsNumber); - cy.get('#search-submit').click(); + cy.getByTestId('nhs-number-input').type(searchPatientPayload.nhsNumber); + cy.getByTestId('search-submit-btn').click(); cy.wait('@search'); // verify patient is active @@ -65,7 +65,7 @@ describe('GP View Lloyd George Workflow', () => { assertEmptyLloydGeorgeCard(); }); - it('displays an empty Lloyd George card when the backend API call fails', () => { + it('displays an empty Lloyd George card when the Lloyd George Stitch API call fails', () => { cy.intercept('GET', '/LloydGeorgeStitch*', { statusCode: 500, }); @@ -83,6 +83,7 @@ describe('GP View Lloyd George Workflow', () => { statusCode: 200, body: viewLloydGeorgePayload, }).as('lloydGeorgeStitch'); + cy.get('#verify-submit').click(); cy.wait('@lloydGeorgeStitch'); }); @@ -142,7 +143,7 @@ describe('GP View Lloyd George Workflow', () => { }); // TODO - PRMDR-401 - implement error scenario in UI and amend assertions accordingly - it.skip('displays an error when the document manifest backend API call fails', () => { + it.skip('displays an error when the document manifest API call fails', () => { cy.intercept('GET', '/DocumentManifest*', { statusCode: 500, }).as('documentManifest'); @@ -153,9 +154,110 @@ describe('GP View Lloyd George Workflow', () => { cy.wait('@documentManifest'); // Assert - cy.contains( - 'appropriate error for when the document manifest backend API call fails', - ).should('be.visible'); + cy.contains('appropriate error for when the document manifest API call fails').should( + 'be.visible', + ); + }); + }); + + context('Delete Lloyd George document', () => { + beforeEach(() => { + cy.intercept('GET', '/LloydGeorgeStitch*', { + statusCode: 200, + body: viewLloydGeorgePayload, + }).as('lloydGeorgeStitch'); + + cy.get('#verify-submit').click(); + cy.wait('@lloydGeorgeStitch'); + + cy.getByTestId('actions-menu').click(); + cy.getByTestId('delete-all-files-link').click(); + }); + + it('allows a GP user to delete the Lloyd George document of an active patient', () => { + // assert delete confirmation page is as expected + cy.contains('Are you sure you want to permanently delete files for:').should( + 'be.visible', + ); + cy.contains('GivenName Surname').should('be.visible'); + cy.contains('NHS number: 900 000 0009').should('be.visible'); + cy.contains('Date of birth: 01 January 1970').should('be.visible'); + + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG`, + { + statusCode: 200, + body: 'Success', + }, + ).as('documentDelete'); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + cy.wait('@documentDelete'); + + // assert delete success page is as expected + cy.contains('Deletion complete').should('be.visible'); + cy.contains('12 files from the Lloyd George record of:').should('be.visible'); + cy.contains('GivenName Surname').should('be.visible'); + cy.contains('(NHS number: 900 000 0009)').should('be.visible'); + + cy.getByTestId('lg-return-btn').click(); + + // assert user is returned to view Lloyd George page + cy.contains('Lloyd George record').should('be.visible'); + cy.contains('No documents are available').should('be.visible'); + cy.getByTestId('pdf-card').should('be.visible'); + }); + + it('returns user to view Lloyd George page on cancel of delete', () => { + // cancel delete + cy.getByTestId('no-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + // assert user is returned to view Lloyd George page + cy.contains('Lloyd George record').should('be.visible'); + cy.getByTestId('pdf-card').should('be.visible'); + cy.getByTestId('pdf-viewer').should('be.visible'); + }); + + it('displays an error when the delete Lloyd George document API call fails', () => { + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG`, + { + statusCode: 500, + body: 'Failed to delete documents', + }, + ).as('documentDelete'); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + cy.wait('@documentDelete'); + + // assert + cy.getByTestId('service-error').should('be.visible'); + }); + + it('displays an error on delete attempt when no Lloyd George record exists for the patient', () => { + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG`, + { + statusCode: 404, + body: 'No documents available', + }, + ).as('documentDelete'); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + cy.wait('@documentDelete'); + + // assert + cy.getByTestId('service-error').should('be.visible'); }); }); diff --git a/app/cypress/e2e/0-ndr-core-tests/pcse_download_workflow_step2_individual_patient_search_and_verify.cy.js b/app/cypress/e2e/0-ndr-core-tests/pcse_download_workflow_step2_individual_patient_search_and_verify.cy.js index 5463e4b52..dfe4e0ced 100644 --- a/app/cypress/e2e/0-ndr-core-tests/pcse_download_workflow_step2_individual_patient_search_and_verify.cy.js +++ b/app/cypress/e2e/0-ndr-core-tests/pcse_download_workflow_step2_individual_patient_search_and_verify.cy.js @@ -1,3 +1,5 @@ +import searchPatientPayload from '../../fixtures/requests/GET_SearchPatient.json'; + describe('PCSE Download Workflow: Access and download found files', () => { // env vars const baseUrl = Cypress.env('CYPRESS_BASE_URL') ?? 'http://localhost:3000/'; @@ -42,9 +44,9 @@ describe('PCSE Download Workflow: Access and download found files', () => { body: patient, }).as('search'); - cy.get('#nhs-number-input').click(); - cy.get('#nhs-number-input').type(testPatient); - cy.get('#search-submit').click(); + cy.getByTestId('nhs-number-input').click(); + cy.getByTestId('nhs-number-input').type(testPatient); + cy.getByTestId('search-submit-btn').click(); cy.wait('@search'); }; @@ -241,4 +243,100 @@ describe('PCSE Download Workflow: Access and download found files', () => { cy.get('#start-again-link').click(); cy.url().should('eq', baseUrl); }); + + context.only('delete all documents relating to a patient', () => { + beforeEach(() => { + cy.intercept('GET', '/SearchPatient*', { + statusCode: 200, + body: searchPatientPayload, + }).as('patientSearch'); + + cy.getByTestId('nhs-number-input').click(); + cy.getByTestId('nhs-number-input').type(testPatient); + cy.getByTestId('search-submit-btn').click(); + cy.wait('@patientSearch'); + + cy.intercept('GET', '/SearchDocumentReferences*', { + statusCode: 200, + body: searchDocumentReferencesResponse, + }).as('documentSearch'); + + cy.get('#verify-submit').click(); + + cy.wait('@documentSearch'); + }); + + it('allows a PCSE user to delete all documents relating to a patient', () => { + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG,ARF`, + { + statusCode: 200, + body: 'Success', + }, + ).as('documentDelete'); + + cy.getByTestId('delete-all-documents-btn').click(); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + cy.wait('@documentDelete'); + + // assert delete success page is as expected + cy.contains('Deletion complete').should('be.visible'); + cy.contains('2 files from the record of:').should('be.visible'); + cy.contains('GivenName Surname').should('be.visible'); + cy.contains('(NHS number: 900 000 0009)').should('be.visible'); + }); + + it('returns user to download documents page on cancel of delete', () => { + cy.getByTestId('delete-all-documents-btn').click(); + + // cancel delete + cy.getByTestId('no-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + // assert user is returned to download documents page + cy.contains('Download electronic health records and attachments').should('be.visible'); + }); + + it('displays an error when the delete document API call fails', () => { + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG,ARF`, + { + statusCode: 500, + body: 'Failed to delete documents', + }, + ).as('documentDelete'); + + cy.getByTestId('delete-all-documents-btn').click(); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + // assert + cy.getByTestId('service-error').should('be.visible'); + }); + + it('displays an error on delete attempt when documents exist for the patient', () => { + cy.intercept( + 'DELETE', + `/DocumentDelete?patientId=${searchPatientPayload.nhsNumber}&docType=LG,ARF`, + { + statusCode: 404, + body: 'No documents available', + }, + ).as('documentDelete'); + + cy.getByTestId('delete-all-documents-btn').click(); + + cy.getByTestId('yes-radio-btn').click(); + cy.getByTestId('delete-submit-btn').click(); + + // assert + cy.getByTestId('service-error').should('be.visible'); + }); + }); }); diff --git a/app/src/components/blocks/deleteDocumentsStage/DeleteDocumentsStage.tsx b/app/src/components/blocks/deleteDocumentsStage/DeleteDocumentsStage.tsx index d2e55a615..0e74e09f0 100644 --- a/app/src/components/blocks/deleteDocumentsStage/DeleteDocumentsStage.tsx +++ b/app/src/components/blocks/deleteDocumentsStage/DeleteDocumentsStage.tsx @@ -126,6 +126,7 @@ function DeleteDocumentsStage({ inputRef={deleteDocsRef} {...radioProps} id="yes-radio-button" + data-testid="yes-radio-btn" defaultChecked > Yes @@ -135,6 +136,7 @@ function DeleteDocumentsStage({ inputRef={deleteDocsRef} {...radioProps} id="no-radio-button" + data-testid="no-radio-btn" > No @@ -143,7 +145,7 @@ function DeleteDocumentsStage({ {deletionStage === SUBMISSION_STATE.PENDING ? ( ) : ( - + Continue )} diff --git a/app/src/components/blocks/deletionConfirmationStage/DeletionConfirmationStage.tsx b/app/src/components/blocks/deletionConfirmationStage/DeletionConfirmationStage.tsx index 5b6600466..ad0104007 100644 --- a/app/src/components/blocks/deletionConfirmationStage/DeletionConfirmationStage.tsx +++ b/app/src/components/blocks/deletionConfirmationStage/DeletionConfirmationStage.tsx @@ -47,7 +47,7 @@ function DeletionConfirmationStage({ numberOfFiles, patientDetails, setStage, us {userType === USER_ROLE.GP ? ( - + Return to patient's Lloyd George record page ) : ( diff --git a/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx b/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx index 6a4874cdb..8eaba8a26 100644 --- a/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx +++ b/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx @@ -98,6 +98,7 @@ const DocumentSearchResultsOptions = (props: Props) => { { role="alert" tabIndex={-1} id="service-error" + data-testid="service-error" > Sorry, the service is currently unavailable. diff --git a/app/src/pages/patientSearchPage/PatientSearchPage.tsx b/app/src/pages/patientSearchPage/PatientSearchPage.tsx index c2fb40a62..88ae90597 100644 --- a/app/src/pages/patientSearchPage/PatientSearchPage.tsx +++ b/app/src/pages/patientSearchPage/PatientSearchPage.tsx @@ -122,6 +122,7 @@ function PatientSearchPage({ role }: Props) { ) : ( - + Search )}
{userType === USER_ROLE.GP ? ( - + Return to patient's Lloyd George record page ) : ( diff --git a/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx b/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx index 6a4874cdb..8eaba8a26 100644 --- a/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx +++ b/app/src/components/blocks/documentSearchResultsOptions/DocumentSearchResultsOptions.tsx @@ -98,6 +98,7 @@ const DocumentSearchResultsOptions = (props: Props) => { { role="alert" tabIndex={-1} id="service-error" + data-testid="service-error" > Sorry, the service is currently unavailable. diff --git a/app/src/pages/patientSearchPage/PatientSearchPage.tsx b/app/src/pages/patientSearchPage/PatientSearchPage.tsx index c2fb40a62..88ae90597 100644 --- a/app/src/pages/patientSearchPage/PatientSearchPage.tsx +++ b/app/src/pages/patientSearchPage/PatientSearchPage.tsx @@ -122,6 +122,7 @@ function PatientSearchPage({ role }: Props) { ) : ( - + Search )}