Skip to content

Commit

Permalink
Review feedback + some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen committed Aug 20, 2024
1 parent f77f26f commit 7d4bd37
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
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 @@ -41,7 +41,7 @@ export class RegistrationAndEditPage {
readonly cityVillageInput = () => this.page.locator('#cityVillage');
readonly phoneInput = () => this.page.locator('#phone');
readonly emailInput = () => this.page.locator('#email');
readonly createPatientButton = () => this.page.locator('button[type=submit]');
readonly createPatientButton = () => this.page.getByRole('button', { name: /register patient/i });

async goto(editPatientUuid?: string) {
await this.page.goto(editPatientUuid ? `patient/${editPatientUuid}/edit` : 'patient-registration');
Expand Down
73 changes: 48 additions & 25 deletions e2e/specs/register-new-patient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,49 @@ test('Register a new patient', async ({ page }) => {
await patientRegistrationPage.waitUntilTheFormIsLoaded();
});

await test.step('And then I fill the registration form and then click the `Submit` button', async () => {
await test.step('And then I fill the registration form with the data in `formValues` and then click the `Submit` button', async () => {
await patientRegistrationPage.fillPatientRegistrationForm(formValues);
});

await test.step('Then I should see a success notification', async () => {
await expect(page.getByText(/new patient created/i)).toBeVisible();
});

await test.step("Then I should be redirected to the new patient's chart page", async () => {
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 test.step("And I should the newly registered patient's details displayed in the patient banner", async () => {
await test.step("And I should see the newly registered patient's details displayed in the patient banner", async () => {
const patientBanner = page.locator('header[aria-label="patient banner"]');
await patientBanner.waitFor({ state: 'visible' });

await expect(page.getByLabel('patient banner').getByText(/johnny donny ronny/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/male/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/4 yrs, 6 mths/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/01 Feb 2020/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/OpenMRS ID/i)).toBeVisible();
await expect(patientBanner).toBeVisible();
await expect(patientBanner.getByText('Johnny Donny Ronny')).toBeVisible();
await expect(patientBanner.getByText(/male/i)).toBeVisible();
await expect(patientBanner.getByText(/4 yrs, 6 mths/i)).toBeVisible();
await expect(patientBanner.getByText(/01 Feb 2020/i)).toBeVisible();
await expect(patientBanner.getByText(/OpenMRS ID/i)).toBeVisible();
});

await test.step('And when I click the `Show details` button in the patient banner', async () => {
await page
.getByLabel('patient banner')
.getByRole('button', { name: /show details/i })
.click();
await expect(page.getByLabel('patient banner').getByRole('button', { name: /hide details/i })).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/^address$/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/address line 1: bom jesus street/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/city: recife/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/state: pernambuco/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/country: brazil/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/contact details/i)).toBeVisible();
await expect(page.getByLabel('patient banner').getByText(/telephone number: 5555551234/i)).toBeVisible();
});

await test.step("Then I should see the patient's address and contact details displayed in the patient banner", async () => {
const patientBanner = page.locator('header[aria-label="patient banner"]');

await expect(patientBanner.getByRole('button', { name: /hide details/i })).toBeVisible();
await expect(patientBanner.getByText(/^address$/i)).toBeVisible();
await expect(patientBanner.getByText(/address line 1: Bom Jesus Street/i)).toBeVisible();
await expect(patientBanner.getByText(/city: Recife/i)).toBeVisible();
await expect(patientBanner.getByText(/state: Pernambuco/i)).toBeVisible();
await expect(patientBanner.getByText(/country: Brazil/i)).toBeVisible();
await expect(patientBanner.getByText(/contact details/i)).toBeVisible();
await expect(patientBanner.getByText(/telephone number: 5555551234/i)).toBeVisible();
});
});

Expand All @@ -73,11 +84,11 @@ test('Register an unknown patient', async ({ api, page }) => {
await patientRegistrationPage.waitUntilTheFormIsLoaded();
});

await test.step(`And I click on the unknown 'patient's name' tab`, async () => {
await test.step("And I click the `No` tab in the `Patient's Name is Known?` field", async () => {
await page.getByRole('tab', { name: /no/i }).first().click();
});

await test.step('And I select `female` as the patient gender', async () => {
await test.step('And then I set the gender to `Female`', async () => {
await page
.locator('label')
.filter({ hasText: /female/i })
Expand All @@ -86,11 +97,11 @@ test('Register an unknown patient', async ({ api, page }) => {
.click();
});

await test.step('And I click on the unknown `Date of Birth` tab', async () => {
await test.step('And then I click on the `No` tab in the "Date of Birth Known" field', async () => {
await page.getByRole('tab', { name: /no/i }).nth(1).click();
});

await test.step('And I fill the field for estimated age in years', async () => {
await test.step('And then I fill in 25 as the estimated age in years', async () => {
const estimatedAgeField = await page.getByLabel(/estimated age in years/i);
await estimatedAgeField.clear();
await estimatedAgeField.fill('25');
Expand All @@ -100,13 +111,25 @@ test('Register an unknown patient', async ({ api, page }) => {
await page.getByRole('button', { name: /register patient/i }).click();
});

await test.step('Then I should see a success toast notification', async () => {
await test.step('Then I should see a success notification', async () => {
await expect(page.getByText(/new patient created/i)).toBeVisible();
});

await test.step('And I should see the newly recorded unknown patient dispalyed on the dashboard', async () => {
const patient = await getPatient(api, /patient\/(.+)\/chart/.exec(page.url())?.[1]);
expect(patient?.person?.display).toBe('UNKNOWN UNKNOWN');
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 test.step("And I should see the newly registered patient's details displayed in the patient banner", async () => {
const patientBanner = page.locator('header[aria-label="patient banner"]');

expect(patientBanner).toBeVisible();
await expect(patientBanner.getByText('Unknown Unknown')).toBeVisible();
await expect(patientBanner.getByText(/female/i)).toBeVisible();
await expect(patientBanner.getByText(/25 yrs/i)).toBeVisible();
await expect(patientBanner.getByText(/01 Jan 1999/i)).toBeVisible();
await expect(patientBanner.getByText(/OpenMRS ID/i)).toBeVisible();
});
});

Expand Down

0 comments on commit 7d4bd37

Please # to comment.