Skip to content

Commit

Permalink
(test) O3-4227: Add E2E Test for Marking an Existing Patient as Decea…
Browse files Browse the repository at this point in the history
…sed (#2129)

---------

Co-authored-by: Daud Kakumirizi <[email protected]>
Co-authored-by: Jayasanka Weerasinghe <[email protected]>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent d90af57 commit c73e83d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions e2e/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './immunizations-page';
export * from './medications-page';
export * from './orders-page';
export * from './program-page';
export * from './mark-patient-deceased-page';
export * from './results-viewer-page';
export * from './visits-page';
export * from './vitals-and-biometrics-page';
10 changes: 10 additions & 0 deletions e2e/pages/mark-patient-deceased-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type Page } from '@playwright/test';

export class MarkPatientDeceasedPage {
constructor(readonly page: Page) {}

async goTo(patientUuid: string) {
await this.page.goto('/openmrs/spa/patient/' + patientUuid + '/chart/Patient%20Summary');
}

}
60 changes: 60 additions & 0 deletions e2e/specs/mark-patient-deceased.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from '@playwright/test';
import { generateRandomPatient, deletePatient, type Patient } from '../commands';
import { test } from '../core';
import { MarkPatientDeceasedPage } from '../pages/mark-patient-deceased-page';

let patient: Patient;

test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
});

test('Mark a patient as deceased', async ({ page }) => {
const markPatientDeceasedPage = new MarkPatientDeceasedPage(page);
const todayDate = new Date().toLocaleDateString('en-GB').replace(/\//g, '-');
const causeOfDeath = 'Neoplasm';
const actionsButton = () => page.getByRole('button', { name: /actions/i });
const markDeceasedMenuItem = () => page.getByRole('menuitem', { name: /mark patient deceased/i });
const deathDetailsForm = () => page.locator('form');
const dateOfDeathInput = () => page.getByPlaceholder(/dd\/mm\/yyyy/i);
const saveAndCloseButton = () => page.getByRole('button', { name: /save and close/i });

await test.step('Given that I have a patient and I am on the Patient’s chart page', async () => {
await markPatientDeceasedPage.goTo(patient.uuid);
});

await test.step('When I click on the "Actions" button and select "Mark patient deceased"', async () => {
await actionsButton().click();
await markDeceasedMenuItem().click();
});

await test.step('Then I should see a form to enter the patient\'s death details', async () => {
await expect(deathDetailsForm()).toBeVisible();
await expect(dateOfDeathInput()).toBeVisible();
await expect(page.getByRole('radio', { name: causeOfDeath })).toBeVisible();
});

await test.step('When I enter the "Date of death" to today’s date', async () => {
await dateOfDeathInput().fill(todayDate);
await page.keyboard.press('Enter');
});

await test.step('And the "Cause of death" to Neoplasm', async () => {
await page.locator('text=Neoplasm').click();
});

await test.step('And I click "Save and close"', async () => {
await page.getByRole('button', { name: /save and close/i }).click();
});

await test.step('Then I should see a “deceased” patient tag in the patient banner', async () => {
const deceasedTagLocator = page.locator(
'[data-extension-id="deceased-patient-tag"] span[title="Deceased"]'
);
await expect(deceasedTagLocator).toBeVisible();
});
});

test.afterEach(async ({ api }) => {
await deletePatient(api, patient.uuid);
});

0 comments on commit c73e83d

Please sign in to comment.