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-4227: Add e2e test for marking a patient as deceased #2156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions e2e/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './program-page';
export * from './results-viewer-page';
export * from './visits-page';
export * from './vitals-and-biometrics-page';
export * from './mark-patient-deceased-page';
35 changes: 35 additions & 0 deletions e2e/pages/mark-patient-deceased-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type Page } from '@playwright/test';

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

readonly actionsButton = () => this.page.getByRole('button', { name: /actions/i });
readonly markDeceasedMenuItem = () => this.page.getByRole('menuitem', { name: /mark patient deceased/i });
readonly deathDetailsForm = () => this.page.locator('form');
readonly dateOfDeathInput = () => this.page.getByPlaceholder(/dd\/mm\/yyyy/i);
readonly causeOfDeathRadio = (cause: string) => this.page.getByRole('radio', { name: cause });
readonly saveAndCloseButton = () => this.page.getByRole('button', { name: /save and close/i });
readonly deceasedTag = () => this.page.getByText(/deceased/i);

async goToPatientChart(patientUuid: string) {
await this.page.goto(`/openmrs/spa/patient/${patientUuid}/chart/Patient%20Summary`);
}

async openMarkDeceasedForm() {
await this.actionsButton().click();
await this.markDeceasedMenuItem().click();
}

async fillDeathDetails(date: string, causeOfDeath: string) {
await this.dateOfDeathInput().fill(date);
await this.causeOfDeathRadio(causeOfDeath).click();
}

async saveAndClose() {
await this.saveAndCloseButton().click();
}

async verifyDeceasedTag() {
await expect(this.deceasedTag()).toBeVisible();
}
dilankavishka marked this conversation as resolved.
Show resolved Hide resolved
}
43 changes: 43 additions & 0 deletions e2e/specs/mark-patient-deceased.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect } from '@playwright/test';
import { generateRandomPatient, deletePatient, type Patient } from '../commands';
import { test } from '../core';
import { MarkPatientDeceasedPage } from '../pages';

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/cancer';

await test.step('When I go to the Patient’s chart page', async () => {
await markPatientDeceasedPage.goToPatientChart(patient.uuid);
});

await test.step('And I select "Mark patient deceased" from the Actions menu', async () => {
await markPatientDeceasedPage.openMarkDeceasedForm();
});

await test.step('Then I should see a form to enter death details', async () => {
await expect(markPatientDeceasedPage.deathDetailsForm()).toBeVisible();
await expect(markPatientDeceasedPage.dateOfDeathInput()).toBeVisible();
await expect(markPatientDeceasedPage.causeOfDeathRadio(causeOfDeath)).toBeVisible();
});

await test.step('When I fill out the death details and save', async () => {
await markPatientDeceasedPage.fillDeathDetails(todayDate, causeOfDeath);
await markPatientDeceasedPage.saveAndClose();
});
dilankavishka marked this conversation as resolved.
Show resolved Hide resolved

await test.step('Then I should see a “deceased” tag in the patient banner', async () => {
await markPatientDeceasedPage.verifyDeceasedTag();
});
});

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