Skip to content

Commit

Permalink
PRMDR-316 add cypress tests for gp and pcse document deletion (#126)
Browse files Browse the repository at this point in the history
* add cypress tests for gp and pcse document deletion
  • Loading branch information
carlsmith101 authored Nov 2, 2023
1 parent b0ba6a0 commit 987f5d2
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 13 deletions.
116 changes: 109 additions & 7 deletions app/cypress/e2e/0-ndr-core-tests/gp_view_lloyd_george_workflow.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
Expand All @@ -83,6 +83,7 @@ describe('GP View Lloyd George Workflow', () => {
statusCode: 200,
body: viewLloydGeorgePayload,
}).as('lloydGeorgeStitch');

cy.get('#verify-submit').click();
cy.wait('@lloydGeorgeStitch');
});
Expand Down Expand Up @@ -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');
Expand All @@ -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');
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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/';
Expand Down Expand Up @@ -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');
};

Expand Down Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function DeleteDocumentsStage({
inputRef={deleteDocsRef}
{...radioProps}
id="yes-radio-button"
data-testid="yes-radio-btn"
defaultChecked
>
Yes
Expand All @@ -135,6 +136,7 @@ function DeleteDocumentsStage({
inputRef={deleteDocsRef}
{...radioProps}
id="no-radio-button"
data-testid="no-radio-btn"
>
No
</Radios.Radio>
Expand All @@ -143,7 +145,7 @@ function DeleteDocumentsStage({
{deletionStage === SUBMISSION_STATE.PENDING ? (
<SpinnerButton id="delete-docs-spinner" status="Deleting..." disabled={true} />
) : (
<Button type="submit" id="lg-delete-submit">
<Button type="submit" id="delete-submit-button" data-testid="delete-submit-btn">
Continue
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function DeletionConfirmationStage({ numberOfFiles, patientDetails, setStage, us
</Card>
<p style={{ marginTop: 40 }}>
{userType === USER_ROLE.GP ? (
<ButtonLink onClick={handleClick}>
<ButtonLink onClick={handleClick} data-testid="lg-return-btn">
Return to patient's Lloyd George record page
</ButtonLink>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const DocumentSearchResultsOptions = (props: Props) => {
</a>
<ButtonLink
className="nhsuk-button nhsuk-button--secondary"
data-testid="delete-all-documents-btn"
style={{ marginLeft: 72 }}
role="button"
onClick={deleteAllDocuments}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ServiceError = ({ message }: Props) => {
role="alert"
tabIndex={-1}
id="service-error"
data-testid="service-error"
>
<ErrorSummary.Title id={serviceErrorSummaryId}>
Sorry, the service is currently unavailable.
Expand Down
3 changes: 2 additions & 1 deletion app/src/pages/patientSearchPage/PatientSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function PatientSearchPage({ role }: Props) {
</Fieldset.Legend>
<Input
id="nhs-number-input"
data-testid="nhs-number-input"
label="Enter NHS number"
hint="A 10-digit number, for example, 485 777 3456"
type="text"
Expand All @@ -146,7 +147,7 @@ function PatientSearchPage({ role }: Props) {
disabled={true}
/>
) : (
<Button type="submit" id="search-submit">
<Button type="submit" id="search-submit" data-testid="search-submit-btn">
Search
</Button>
)}
Expand Down

0 comments on commit 987f5d2

Please sign in to comment.