Skip to content

Commit

Permalink
(test) Enhance registration e2e tests (#1481)
Browse files Browse the repository at this point in the history
* (test) Enhance registration e2e tests

This PR enhances the registration e2e tests by:

- Adding address hierarchy search input verification
- Adding explicit visibility checks for address template fields
- Using a more reliable URL pattern for patient chart page
- Adding a try-catch block for patient cleanup
- Replacing fixed timeout with test.slow()

* Review feedback - remove extraneous assertions
  • Loading branch information
denniskigen authored Feb 10, 2025
1 parent 71bfc36 commit 6364d3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions e2e/pages/registration-and-edit-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class RegistrationAndEditPage {
readonly birthDateInput = () => this.page.locator('#birthdate');
readonly birthdateDayInput = () => this.birthDateInput().locator('[data-type="day"]');
readonly birthdateMonthInput = () => this.birthDateInput().locator('[data-type="month"]');
readonly addressHierarchySearchInput = () => this.page.getByPlaceholder(/search address/i);
readonly birthdateYearInput = () => this.birthDateInput().locator('[data-type="year"]');
readonly address1Input = () => this.page.locator('#address1');
readonly countryInput = () => this.page.locator('#country');
Expand Down
41 changes: 26 additions & 15 deletions e2e/specs/register-new-patient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { expect } from '@playwright/test';
import { test } from '../core';
import { deletePatient } from '../commands';
import { RegistrationAndEditPage } from '../pages';
import { test } from '../core';
import { type PatientRegistrationFormValues } from '../types';
import { deletePatient } from '../commands';

const PATIENT_CHART_URL = /\/patient\/(?<uuid>[a-f0-9-]{36})\/chart/i;
let patientUuid: string;

test('Register a new patient', async ({ page }) => {
test.setTimeout(5 * 60 * 1000);
test.slow();
const patientRegistrationPage = new RegistrationAndEditPage(page);

// TODO: Add email field after fixing O3-1883 (https://issues.openmrs.org/browse/O3-1883)
Expand All @@ -32,6 +33,14 @@ test('Register a new patient', async ({ page }) => {
});

await test.step('And then I fill the registration form with the data in `formValues` and then click the `Submit` button', async () => {
// Check for explicit visibility of address template fields
await expect(patientRegistrationPage.addressHierarchySearchInput()).toBeVisible();
await expect(patientRegistrationPage.address1Input()).toBeVisible();
await expect(patientRegistrationPage.countryInput()).toBeVisible();
await expect(patientRegistrationPage.stateProvinceInput()).toBeVisible();
await expect(patientRegistrationPage.cityVillageInput()).toBeVisible();

// Fill and submit the form
await patientRegistrationPage.fillPatientRegistrationForm(formValues);
});

Expand All @@ -40,9 +49,8 @@ test('Register a new patient', async ({ page }) => {
});

await test.step("And I should be redirected to the new patient's chart page", async () => {
const patientChartUrlRegex = new RegExp('^[\\w\\d:\\/.-]+\\/patient\\/[\\w\\d-]+\\/chart\\/.*$');
await page.waitForURL(patientChartUrlRegex);
await expect(page).toHaveURL(patientChartUrlRegex);
await page.waitForURL(PATIENT_CHART_URL);
await expect(page).toHaveURL(PATIENT_CHART_URL);
});

await test.step("And I should see the newly registered patient's details displayed in the patient banner", async () => {
Expand Down Expand Up @@ -76,10 +84,10 @@ test('Register a new patient', async ({ page }) => {
});
});

test('Register an unknown patient', async ({ api, page }) => {
test('Register an unknown patient', async ({ page }) => {
const patientRegistrationPage = new RegistrationAndEditPage(page);

await test.step('When I visit the patient registration page', async () => {
await test.step('When I visit the registration page', async () => {
await patientRegistrationPage.goto();
await patientRegistrationPage.waitUntilTheFormIsLoaded();
});
Expand All @@ -103,9 +111,7 @@ test('Register an unknown patient', async ({ api, page }) => {

const estimatedAge = 25;
await test.step(`And then I fill in ${estimatedAge} as the estimated age in years`, async () => {
const estimatedAgeField = page.getByLabel(/estimated age in years/i);
await estimatedAgeField.clear();
await estimatedAgeField.fill('' + estimatedAge);
await page.getByLabel(/estimated age in years/i).fill(`${estimatedAge}`);
});

await test.step('And I click on the submit button', async () => {
Expand All @@ -117,9 +123,8 @@ test('Register an unknown patient', async ({ api, page }) => {
});

await test.step("And I should be redirected to the new patient's chart page", async () => {
const patientChartUrlRegex = new RegExp('^[\\w\\d:\\/.-]+\\/patient\\/[\\w\\d-]+\\/chart\\/.*$');
await page.waitForURL(patientChartUrlRegex);
await expect(page).toHaveURL(patientChartUrlRegex);
await page.waitForURL(PATIENT_CHART_URL);
await expect(page).toHaveURL(PATIENT_CHART_URL);
});

await test.step("And I should see the newly registered patient's details displayed in the patient banner", async () => {
Expand All @@ -136,5 +141,11 @@ test('Register an unknown patient', async ({ api, page }) => {
});

test.afterEach(async ({ api }) => {
await deletePatient(api, patientUuid);
if (patientUuid) {
try {
await deletePatient(api, patientUuid);
} catch (error) {
console.error(`Error deleting patient ${patientUuid}:`, error);
}
}
});

0 comments on commit 6364d3a

Please sign in to comment.