Skip to content

Commit

Permalink
PRMDR-264 View a Lloyd George Document e2e tests (#87)
Browse files Browse the repository at this point in the history
* [PRMDR-264] create set up for LG view e2e tests and test it navigates successfully to the page

* [PRMDR-264] add test for patient info and lg card

* add remaining view lloyd george doc tests

* add full screen checks, force GMT time on local cypress

* update following PR comments

---------

Co-authored-by: RachelHowellNHS <rachel.howell6@nhs.net>
  • Loading branch information
carlsmith101 and RachelHowellNHS authored Oct 13, 2023
1 parent 56075b7 commit 78edf3f
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ docker-down:
docker-compose -f ./app/docker-compose.yml down

cypress-open:
npm --prefix ./app run cypress
TZ=GMT npm --prefix ./app run cypress
115 changes: 115 additions & 0 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
@@ -0,0 +1,115 @@
import viewLloydGeorgePayload from '../../fixtures/requests/GET_LloydGeorgeStitch.json';
import searchPatientPayload from '../../fixtures/requests/GET_SearchPatient.json';

const baseUrl = Cypress.env('CYPRESS_BASE_URL') ?? 'http://localhost:3000/';

describe('GP View Lloyd George Workflow', () => {
beforeEach(() => {
// Arrange
navigateToLgPage();
});

it('allows a GP user to view the Lloyd George document of an active patient', () => {
// Act
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 200,
body: viewLloydGeorgePayload,
});
cy.get('#verify-submit').click();

// Assert
assertPatientInfo();
cy.getCy('pdf-card')
.should('include.text', 'Lloyd George record')
.should('include.text', 'Last updated: 09 October 2023 at 15:41:38')
.should('include.text', '12 files | File size: 502 KB | File format: PDF');
cy.getCy('pdf-viewer').should('be.visible');

// Act - open full screen view
cy.getCy('full-screen-btn').click();

// Assert
assertPatientInfo();
cy.getCy('pdf-card').should('not.exist');
cy.getCy('pdf-viewer').should('be.visible');

// Act - close full screen view
cy.getCy('back-link').click();

// Assert
cy.getCy('pdf-card').should('be.visible');
cy.getCy('pdf-viewer').should('be.visible');
});

it('displays an empty Lloyd George card when no Lloyd George record exists for the patient', () => {
// Act
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 404,
});
cy.get('#verify-submit').click();

// Assert
assertPatientInfo();
assertEmptyLloydGeorgeCard();
});

it('displays an empty Lloyd George card when the backend API call fails', () => {
// Act
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 500,
});
cy.get('#verify-submit').click();

//Assert
assertPatientInfo();
assertEmptyLloydGeorgeCard();
});

const navigateToLgPage = () => {
// login and navigate to search
cy.intercept('GET', '/Auth/TokenRequest*', {
statusCode: 200,
body: {
organisations: [
{
org_name: 'PORTWAY LIFESTYLE CENTRE',
ods_code: 'A470',
role: 'DEV',
},
],
authorisation_token: '111xxx222',
},
}).as('auth');
cy.visit(baseUrl + 'auth-callback');
cy.wait('@auth');

cy.get(`#gp-radio-button`).click();
cy.get('#role-submit-button').click();

// search patient
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
body: searchPatientPayload,
}).as('search');
cy.get('#nhs-number-input').type(searchPatientPayload.nhsNumber);
cy.get('#search-submit').click();
cy.wait('@search');

// verify patient is active
cy.get('#active-radio-button').click();
};

const assertPatientInfo = () => {
cy.getCy('patient-name').should(
'have.text',
`${searchPatientPayload.givenName} ${searchPatientPayload.familyName}`,
);
cy.getCy('patient-nhs-number').should('have.text', `NHS number: 900 000 0009`);
cy.getCy('patient-dob').should('have.text', `Date of birth: 01 January 1970`);
};

const assertEmptyLloydGeorgeCard = () => {
cy.getCy('pdf-card').should('include.text', 'Lloyd George record');
cy.getCy('pdf-card').should('include.text', 'No documents are available');
};
});
5 changes: 0 additions & 5 deletions app/cypress/fixtures/example.json

This file was deleted.

6 changes: 6 additions & 0 deletions app/cypress/fixtures/requests/GET_LloydGeorgeStitch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"number_of_files": 12,
"last_updated": "2023-10-09T15:41:38.319508Z",
"presign_url": "https://google.com",
"total_file_size_in_byte": 514495
}
9 changes: 9 additions & 0 deletions app/cypress/fixtures/requests/GET_SearchPatient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"birthDate": "1970-01-01",
"familyName": "Surname",
"givenName": ["GivenName"],
"nhsNumber": "9000000009",
"postalCode": "AA1 1AA",
"superseded": false,
"restricted": false
}
17 changes: 15 additions & 2 deletions app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="cypress" />
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
Expand All @@ -14,7 +15,19 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import './commands';

Cypress.Commands.add('getCy', (selector, ...args) => {
return cy.get(`[data-cy=${selector}]`, ...args);
});

declare global {
namespace Cypress {
interface Chainable {
getCy(value: string): Chainable<Subject>;
}
}
}

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
Loading

0 comments on commit 78edf3f

Please sign in to comment.