Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRMDR-605 UI: Update landing page workflows based on isBSOL #268

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ describe('GP Admin user role has access to the expected GP_ADMIN workflow paths'

cy.login(Roles.GP_ADMIN, isBSOL);

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
if (!isBSOL) {
cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
}

cy.url().should('eq', baseUrl + '/search/patient');

cy.get('#nhs-number-input').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,40 @@ const baseUrl = Cypress.config('baseUrl');

const forbiddenRoutes = ['/patient/download'];

const bsolOptions = [true, false];

describe('GP Clinical user role has access to the expected GP_CLINICAL workflow paths', () => {
context('GP Clinical role has access to expected routes', () => {
it('GP Clinical role has access to Lloyd George View', { tags: 'regression' }, () => {
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
body: patient,
}).as('search');
bsolOptions.forEach((isBSOL) => {
const prefix = isBSOL ? '[BSOL]' : '[Non-BSOL]';
context(`${prefix} GP Clinical role has access to expected routes`, () => {
it('GP Clinical role has access to Lloyd George View', { tags: 'regression' }, () => {
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
body: patient,
}).as('search');

cy.login(Roles.GP_CLINICAL, isBSOL);

cy.login(Roles.GP_CLINICAL);
if (!isBSOL) {
cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
}

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
cy.url().should('eq', baseUrl + '/search/patient');
cy.url().should('eq', baseUrl + '/search/patient');

cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);
cy.get('#search-submit').click();
cy.wait('@search');
cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);
cy.get('#search-submit').click();
cy.wait('@search');

cy.url().should('include', 'verify');
cy.url().should('eq', baseUrl + '/search/patient/verify');
cy.url().should('include', 'verify');
cy.url().should('eq', baseUrl + '/search/patient/verify');

cy.get('#verify-submit').click();
cy.get('#verify-submit').click();

cy.url().should('include', 'lloyd-george-record');
cy.url().should('eq', baseUrl + '/patient/view/lloyd-george-record');
cy.url().should('include', 'lloyd-george-record');
cy.url().should('eq', baseUrl + '/patient/view/lloyd-george-record');
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ describe('PCSE user role has access to the expected GP_ADMIN workflow paths', ()

cy.login(Roles.PCSE);

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
cy.url().should('eq', baseUrl + '/search/patient');

cy.get('#nhs-number-input').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import searchPatientPayload from '../../../fixtures/requests/GET_SearchPatient.j
import { Roles } from '../../../support/roles';

const baseUrl = Cypress.config('baseUrl');
const searchPatientUrl = '/search/patient';

describe('GP Workflow: View Lloyd George record', () => {
const beforeEachConfiguration = (role) => {
cy.login(role);
cy.visit(searchPatientUrl);

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
// search patient
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Roles, roleName } from '../../../support/roles';
describe('GP Workflow: Patient search and verify', () => {
// env vars
const baseUrl = Cypress.config('baseUrl');
const searchPatientUrl = '/search/patient';
const gpRoles = [Roles.GP_ADMIN, Roles.GP_CLINICAL];

const noPatientError = 400;
Expand All @@ -22,9 +23,7 @@ describe('GP Workflow: Patient search and verify', () => {
gpRoles.forEach((role) => {
beforeEach(() => {
cy.login(role);

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
cy.visit(searchPatientUrl);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Roles, roleName } from '../../../support/roles';

// env vars
const baseUrl = Cypress.config('baseUrl');
const searchPatientUrl = '/search/patient';

const formTypes = Object.freeze({
LG: 'LG',
Expand Down Expand Up @@ -33,8 +34,7 @@ const navigateToUploadPage = () => {
body: patient,
}).as('search');

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
cy.visit(searchPatientUrl);
cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ describe('GP Workflow: View Lloyd George record', () => {
statusCode: 200,
body: searchPatientPayload,
}).as('search');
cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
cy.getByTestId('nhs-number-input').type(searchPatientPayload.nhsNumber);
cy.getByTestId('search-submit-btn').click();
cy.wait('@search');
Expand Down
77 changes: 50 additions & 27 deletions app/cypress/e2e/0-ndr-core-tests/homepage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('Home Page', () => {
const baseUrl = Cypress.config('baseUrl');
const startUrl = '/';
const homeUrl = '/home';
const searchPatientUrl = '/search/patient';

beforeEach(() => {
cy.visit(startUrl);
Expand Down Expand Up @@ -51,43 +52,66 @@ describe('Home Page', () => {
cy.get('.nhsuk-header__navigation').should('not.exist');
cy.get('.nhsuk-header__navigation-list').should('not.exist');

cy.login(Roles.GP_CLINICAL);
cy.login(Roles.GP_CLINICAL, true);

cy.url().should('eq', baseUrl + homeUrl);
cy.url().should('eq', baseUrl + searchPatientUrl);
cy.get('.nhsuk-header__navigation').should('exist');
cy.get('.nhsuk-header__navigation-list').should('exist');
},
);

it(
'should display non-BSOL landing page when user is GP_ADMIN role in non-BSOL area',
{ tags: 'regression' },
() => {
cy.login(Roles.GP_ADMIN, false);

cy.url().should('eq', baseUrl + homeUrl);
cy.get('h1').should(
'include.text',
'You’re outside of Birmingham and Solihull (BSOL)',
);

cy.get('.govuk-warning-text__text').should('exist');
cy.get('.govuk-warning-text__text').should(
'include.text',
'Downloading a record will remove it from our storage.',
);
const gpRoles = [Roles.GP_ADMIN, Roles.GP_CLINICAL];
gpRoles.forEach((role) => {
it(
`should display non-BSOL landing page when user is ${Roles[role]} role in non-BSOL area`,
{ tags: 'regression' },
() => {
cy.login(Roles.GP_ADMIN, false);

cy.url().should('eq', baseUrl + homeUrl);
cy.get('h1').should(
'include.text',
'You’re outside of Birmingham and Solihull (BSOL)',
);

cy.get('.govuk-warning-text__text').should('exist');
cy.get('.govuk-warning-text__text').should(
'include.text',
'Downloading a record will remove it from our storage.',
);

cy.get('.nhsuk-header__navigation').should('exist');
cy.get('.nhsuk-header__navigation-list').should('exist');
},
);
});

gpRoles.forEach((role) => {
it(
`should display patient search page when user is ${Roles[role]} role in BSOL area`,
{ tags: 'regression' },
() => {
cy.login(role, true);

cy.url().should('eq', baseUrl + searchPatientUrl);
cy.get('h1').should(
'not.include.text',
'You’re outside of Birmingham and Solihull (BSOL)',
);

cy.get('.nhsuk-header__navigation').should('exist');
cy.get('.nhsuk-header__navigation-list').should('exist');
},
);
});

cy.get('.nhsuk-header__navigation').should('exist');
cy.get('.nhsuk-header__navigation-list').should('exist');
},
);
it(
'should display patient search page when user is GP_ADMIN role in BSOL area',
'should display patient search page when user is PCSE Role',
{ tags: 'regression' },
() => {
cy.login(Roles.GP_ADMIN, true);
cy.login(Roles.PCSE);

cy.url().should('eq', baseUrl + homeUrl);
cy.url().should('eq', baseUrl + searchPatientUrl);
cy.get('h1').should(
'not.include.text',
'You’re outside of Birmingham and Solihull (BSOL)',
Expand Down Expand Up @@ -121,7 +145,6 @@ describe('Home Page', () => {

cy.login(Roles.GP_CLINICAL);

cy.url().should('eq', baseUrl + homeUrl);
cy.get('.nhsuk-header__navigation').should('exist');
cy.get('.nhsuk-header__navigation-list').should('exist');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ describe('PCSE Workflow: Access and download found files', () => {

beforeEach(() => {
cy.login(Roles.PCSE);
cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
});

const navigateToVerify = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ describe('PCSE Workflow: patient search and verify', () => {
beforeEach(() => {
cy.visit(homeUrl);
cy.login(Roles.PCSE);

cy.getByTestId('search-patient-btn').should('exist');
cy.getByTestId('search-patient-btn').click();
});

it(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"role": "GP_CLINICAL",
"authorisation_token": "111xxx222"
"authorisation_token": "111xxx222",
"isBSOL": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"role": "GP_CLINICAL",
"authorisation_token": "111xxx222",
"isBSOL": false
}
4 changes: 2 additions & 2 deletions app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Cypress.Commands.add('login', (role, isBSOL = true) => {
// Login for regression tests
const authCallback = '/auth-callback';
const fixturePath =
role === Roles.GP_ADMIN && !isBSOL
? 'requests/auth/GET_TokenRequest_GP_ADMIN_non_bsol.json'
[Roles.GP_ADMIN, Roles.GP_CLINICAL].includes(role) && !isBSOL
? 'requests/auth/GET_TokenRequest_' + roleName + '_non_bsol.json'
: 'requests/auth/GET_TokenRequest_' + roleName + '.json';

cy.intercept('GET', '/Auth/TokenRequest*', {
Expand Down
66 changes: 18 additions & 48 deletions app/src/pages/homePage/HomePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,47 @@ import { render, screen, waitFor } from '@testing-library/react';
import HomePage from './HomePage';
import useIsBSOL from '../../helpers/hooks/useIsBSOL';
import { routes } from '../../types/generic/routes';
import useRole from '../../helpers/hooks/useRole';
import { REPOSITORY_ROLE } from '../../types/generic/authRole';

const mockedUseNavigate = jest.fn();
jest.mock('react-router', () => ({
useNavigate: () => mockedUseNavigate,
}));

jest.mock('../../helpers/hooks/useIsBSOL');
jest.mock('../../helpers/hooks/useRole');
const mockUseIsBsol = useIsBSOL as jest.Mock;
const mockUseRole = useRole as jest.Mock;

describe('HomePage', () => {
afterEach(() => {
jest.clearAllMocks();
});
describe('BSOL Rendering', () => {

const gpRoles = [REPOSITORY_ROLE.GP_ADMIN, REPOSITORY_ROLE.GP_CLINICAL];

describe('BSOL Rendering for GP roles', () => {
beforeEach(() => {
mockUseIsBsol.mockReturnValue(true);
});

it('renders homepage content', () => {
const contentStrings = [
'This service gives you access to Lloyd George digital health records. ' +
'You may have received a note within a patient record, stating that the record has been digitised.',
'If you are part of a GP practice, you can use this service to:',
'view a patient record',
'remove a patient record',
'If you are managing records on behalf of NHS England, you can:',
'Not every patient will have a digital record available.',
'Before you start',
'You’ll be asked for:',
'your NHS smartcard',
'patient details including their name, date of birth and NHS number',
];
it.each(gpRoles)('[%s] redirect user to search patient page', (role) => {
mockUseRole.mockReturnValue(role);

render(<HomePage />);

contentStrings.forEach((s) => {
expect(screen.getByText(s)).toBeInTheDocument();
});

const downloadPatientRecord = screen.getAllByText('download a patient record');
expect(downloadPatientRecord).toHaveLength(2);

expect(screen.getByText(/Contact the/i)).toBeInTheDocument();
expect(
screen.getByRole('link', {
name: /NHS National Service Desk/i,
}),
).toBeInTheDocument();
expect(
screen.getByText(/if there is an issue with this service or call 0300 303 5678\./i),
).toBeInTheDocument();

expect(screen.getByTestId('search-patient-btn')).toBeInTheDocument();
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.SEARCH_PATIENT);
});
});

it('renders a service link that takes you to service help-desk in a new tab', () => {
describe('PCSE Rendering', () => {
beforeEach(() => {
mockUseRole.mockReturnValue(REPOSITORY_ROLE.PCSE);
});
it('redirect user to search patient page', () => {
render(<HomePage />);

expect(screen.getByText(/Contact the/i)).toBeInTheDocument();
const nationalServiceDeskLink = screen.getByRole('link', {
name: /NHS National Service Desk/i,
});
expect(
screen.getByText(/if there is an issue with this service or call 0300 303 5678/i),
).toBeInTheDocument();

expect(nationalServiceDeskLink).toHaveAttribute(
'href',
'https://digital.nhs.uk/about-nhs-digital/contact-us#nhs-digital-service-desks',
);
expect(nationalServiceDeskLink).toHaveAttribute('target', '_blank');
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.SEARCH_PATIENT);
});
});

Expand Down
Loading
Loading