From c73e83d9ab98a376fc3785f3df9174e8443733c0 Mon Sep 17 00:00:00 2001 From: Viraj Wathsala Gunasinghe Date: Tue, 7 Jan 2025 12:49:30 +0530 Subject: [PATCH] (test) O3-4227: Add E2E Test for Marking an Existing Patient as Deceased (#2129) --------- Co-authored-by: Daud Kakumirizi Co-authored-by: Jayasanka Weerasinghe <33048395+jayasanka-sack@users.noreply.github.com> --- e2e/pages/index.ts | 1 + e2e/pages/mark-patient-deceased-page.ts | 10 +++++ e2e/specs/mark-patient-deceased.spec.ts | 60 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 e2e/pages/mark-patient-deceased-page.ts create mode 100644 e2e/specs/mark-patient-deceased.spec.ts diff --git a/e2e/pages/index.ts b/e2e/pages/index.ts index 8ebeb0db36..8690826c72 100644 --- a/e2e/pages/index.ts +++ b/e2e/pages/index.ts @@ -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'; diff --git a/e2e/pages/mark-patient-deceased-page.ts b/e2e/pages/mark-patient-deceased-page.ts new file mode 100644 index 0000000000..f1003747fd --- /dev/null +++ b/e2e/pages/mark-patient-deceased-page.ts @@ -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'); + } + +} diff --git a/e2e/specs/mark-patient-deceased.spec.ts b/e2e/specs/mark-patient-deceased.spec.ts new file mode 100644 index 0000000000..2db44069bd --- /dev/null +++ b/e2e/specs/mark-patient-deceased.spec.ts @@ -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); +});