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

(test) O3-2722: Add E2E test for returning to home page and patient list page from the patient chart #957

Merged
merged 9 commits into from
Feb 28, 2024
2 changes: 1 addition & 1 deletion e2e/pages/registration-and-edit-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export class RegistrationAndEditPage {

async fillPatientRegistrationForm(formValues: PatientRegistrationFormValues) {
const tryFill = (locator: Locator, value?: string) => value && locator.fill(value);
formValues.sex && (await this.sexRadioButton(formValues.sex).check());
await tryFill(this.givenNameInput(), formValues.givenName);
await tryFill(this.middleNameInput(), formValues.middleName);
await tryFill(this.familyNameInput(), formValues.familyName);
formValues.sex && (await this.sexRadioButton(formValues.sex).check());
await tryFill(this.birthdateInput(), formValues.birthdate);
await tryFill(this.phoneInput(), formValues.phone);
await tryFill(this.emailInput(), formValues.email);
Expand Down
6 changes: 2 additions & 4 deletions e2e/specs/patient-list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '../core';
import { PatientListsPage } from '../pages';
import { HomePage, PatientListsPage } from '../pages';
jayasanka-sack marked this conversation as resolved.
Show resolved Hide resolved
import { expect } from '@playwright/test';
import {
type Cohort,
Expand Down Expand Up @@ -68,14 +68,12 @@ test('Create and edit a patient list', async ({ page }) => {
});

test('Manage patients in a list', async ({ api, page }) => {
const patientListPage = new PatientListsPage(page);
await test.step("When I visit a specific patient list's page", async () => {
const patientListPage = new PatientListsPage(page);
await patientListPage.goto(cohort.uuid);
});

await test.step('Then I should be able to add and remove patients from that list', async () => {
const patientListPage = new PatientListsPage(page);

// Add a patient to the list
createdCohortMember = await addPatientToCohort(api, cohort.uuid, patient.uuid);
await patientListPage.goto(cohort.uuid);
Expand Down
8 changes: 8 additions & 0 deletions e2e/specs/patient-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ test('Search patient by full name', async ({ page, api }) => {
`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`,
);
});

await test.step('When I click on the `Close` button', async () => {
await page.getByRole('button', { name: 'Close' }).click();
});

await test.step('Then I should be redirected to the home page', async () => {
await expect(page).toHaveURL(`${process.env.E2E_BASE_URL}/spa/home`);
});
});

test.afterEach(async ({ api }) => {
Expand Down
181 changes: 181 additions & 0 deletions e2e/specs/return-to-patient-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { test } from '../core';
import { HomePage, PatientListsPage } from '../pages';
jayasanka-sack marked this conversation as resolved.
Show resolved Hide resolved
import { expect } from '@playwright/test';
import {
type Cohort,
type CohortMember,
type Patient,
addPatientToCohort,
deleteCohort,
deletePatient,
generateRandomCohort,
generateRandomPatient,
removePatientFromCohort,
} from '../commands';

let createdCohortMember: CohortMember;
let createdCohortUuid: string;
kdaud marked this conversation as resolved.
Show resolved Hide resolved
let cohort: Cohort;
let patient: Patient;

test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
cohort = await generateRandomCohort(api);
createdCohortMember = await addPatientToCohort(api, cohort.uuid, patient.uuid);
kdaud marked this conversation as resolved.
Show resolved Hide resolved
});

test('Return to patient list from the patient chart', async ({ page }) => {
const homePage = new HomePage(page);
kdaud marked this conversation as resolved.
Show resolved Hide resolved
const patientListPage = new PatientListsPage(page);
await test.step('When I navigate to the patient list', async () => {
kdaud marked this conversation as resolved.
Show resolved Hide resolved
await patientListPage.goto(cohort.uuid);
});

await test.step('And I click on the patient {{name}} in the list', async () => {
kdaud marked this conversation as resolved.
Show resolved Hide resolved
await page.locator('table tbody tr td:nth-child(1) a').click();
});

await test.step('Then I should be redirected to the patient chart', async () => {
await expect(homePage.page).toHaveURL(
`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`,
);
});

await test.step('When I click on the `Close` button', async () => {
await page.getByRole('button', { name: 'Close' }).click();
});

await test.step('Then I should be redirected back to the patient list', async () => {
await expect(page).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
});
});

test('Return to patient list after navigating to visits page from the patient chart', async ({ page }) => {
const homePage = new HomePage(page);
const patientListPage = new PatientListsPage(page);
await test.step('When I navigate to the patient list', async () => {
await patientListPage.goto(cohort.uuid);
});

await test.step('And I click on the patient {{name}} in the list', async () => {
await page.locator('table tbody tr td:nth-child(1) a').click();
});

await test.step('Then I should be redirected to the patient chart', async () => {
await expect(homePage.page).toHaveURL(
`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`,
);
});

await test.step('When I click on the `Open menu` button', async () => {
await page.getByLabel('Open menu').click();
});

await test.step('And I click on the `Visits` link', async () => {
kdaud marked this conversation as resolved.
Show resolved Hide resolved
await page.getByRole('link', { name: 'Visits' }).click();
});

await test.step('And I click on the `Close` button', async () => {
await page.getByRole('button', { name: 'Close' }).click();
});

await test.step('Then I should be redirected back to the patient list', async () => {
await expect(page).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
});
});

test('Return to patient list after navigating to visits and refreshing the page', async ({ page }) => {
const homePage = new HomePage(page);
const patientListPage = new PatientListsPage(page);
await test.step('When I navigate to the patient list', async () => {
await patientListPage.goto(cohort.uuid);
});

await test.step('And I click on the patient {{name}} in the list', async () => {
await page.locator('table tbody tr td:nth-child(1) a').click();
});

await test.step('Then I should be redirected to the patient chart', async () => {
await expect(homePage.page).toHaveURL(
`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`,
);
});

await test.step('When I click on the `Open menu` button', async () => {
await page.getByLabel('Open menu').click();
});

await test.step('And I click on the `Visits` link', async () => {
await page.getByRole('link', { name: 'Visits' }).click();
});

await test.step('And I refesh the page', async () => {
await page.reload();
});

await test.step('And I click on the `Close` button', async () => {
await page.getByRole('button', { name: 'Close' }).click();
});

await test.step('Then I should be redirected back to the patient list', async () => {
await expect(page).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
});
});

test('Return to patient list from the patient chart on a new tab', async ({ page, context }) => {
const homePage = new HomePage(page);
const patientListPage = new PatientListsPage(page);
const locator = await page.locator('table tbody tr td:nth-child(1) a');
const pagePromise = context.waitForEvent('page');
await test.step('When I navigate to the patient list', async () => {
await patientListPage.goto(cohort.uuid);
});

await test.step('And I open the patient link in a new tab', async () => {
await locator.click({ button: 'middle' });
});

let newPage = await pagePromise;
await newPage.bringToFront();

await test.step('Then I should be redirected to the patient chart', async () => {
await expect(newPage).toHaveURL(`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`);
});

await test.step('When I click on the `Close` button', async () => {
await newPage.getByRole('button', { name: 'Close' }).click();
});

await test.step('Then I should be redirected back to the patient list', async () => {
await expect(newPage).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
});

await test.step('And I should have two tabs on the patient list', async () => {
await expect(newPage).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
await page.bringToFront();
await expect(page).toHaveURL(/.*patient-lists/);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));
});
});

test.afterEach(async ({ api }) => {
if (createdCohortMember) {
await removePatientFromCohort(api, createdCohortMember.uuid);
}
jayasanka-sack marked this conversation as resolved.
Show resolved Hide resolved
if (createdCohortUuid) {
await deleteCohort(api, createdCohortUuid);
}
kdaud marked this conversation as resolved.
Show resolved Hide resolved
await deletePatient(api, patient.uuid);
await deleteCohort(api, cohort.uuid);
});
Loading