From d2a3c8afc7288a5d57a61ce2a469b7c16a2a8cfb Mon Sep 17 00:00:00 2001 From: Daud Kakumirizi Date: Thu, 28 Mar 2024 22:07:06 +0300 Subject: [PATCH] (test) O3-3000: Add E2E tests for editing and deleting an allergy (#1761) (test) O3-3OOO: Add E2E tests for editing and deleting an allergy --- e2e/specs/allergies.spec.ts | 143 +++++++++++++++++++++++++++++++ e2e/specs/attachments.spec.ts | 4 +- e2e/specs/conditions.spec.ts | 2 +- e2e/specs/drug-orders.spec.ts | 2 +- e2e/specs/lab-orders.spec.ts | 2 +- e2e/specs/record-allergy.spec.ts | 68 --------------- 6 files changed, 148 insertions(+), 73 deletions(-) create mode 100644 e2e/specs/allergies.spec.ts delete mode 100644 e2e/specs/record-allergy.spec.ts diff --git a/e2e/specs/allergies.spec.ts b/e2e/specs/allergies.spec.ts new file mode 100644 index 0000000000..8f48efb928 --- /dev/null +++ b/e2e/specs/allergies.spec.ts @@ -0,0 +1,143 @@ +import { expect } from '@playwright/test'; +import { generateRandomPatient, deletePatient, type Patient } from '../commands'; +import { test } from '../core'; +import { PatientAllergiesPage } from '../pages'; + +let patient: Patient; + +test.beforeEach(async ({ api }) => { + patient = await generateRandomPatient(api); +}); + +test('Add, edit and delete an allergy', async ({ page }) => { + const allergiesPage = new PatientAllergiesPage(page); + const headerRow = allergiesPage.allergiesTable().locator('thead > tr'); + const dataRow = allergiesPage.allergiesTable().locator('tbody > tr'); + + await test.step('When I visit the Allergies page', async () => { + await allergiesPage.goTo(patient.uuid); + }); + + await test.step('And I click on the `Record allergy intolerance` link to launch the form', async () => { + await page.getByText(/record allergy intolerance/i).click(); + }); + + await test.step('Then I should see the record allergy form launch in the workspace', async () => { + await expect(page.getByText(/record a new allergy/i)).toBeVisible(); + }); + + await test.step('When I select `ACE inhibitors` as the allergy', async () => { + await page.getByPlaceholder(/select the allergen/i).click(); + await page.getByText(/ace inhibitors/i).click(); + }); + + await test.step('And I select `Mental status change` as the reaction', async () => { + await page.getByText(/mental status change/i).click(); + }); + + await test.step('And I select `Mild` as the severity', async () => { + await page.getByText(/mild/i).click(); + }); + + await test.step('And I add a comment for the allergy', async () => { + await page.locator('#comments').fill('Feeling faint and light-headed'); + }); + + await test.step('And I click on the `Save and close` button', async () => { + await page.getByRole('button', { name: /save and close/i }).click(); + }); + + await test.step('Then I should see a success toast notification', async () => { + await expect(page.getByText(/allergy saved/i)).toBeVisible(); + }); + + await test.step('And I should see the newly recorded drug allergen in the list', async () => { + await expect(headerRow).toContainText(/allergen/i); + await expect(headerRow).toContainText(/severity/i); + await expect(headerRow).toContainText(/reaction/i); + await expect(headerRow).toContainText(/onset date and comments/i); + await expect(dataRow).toContainText(/ace inhibitors/i); + await expect(dataRow).toContainText(/mild/i); + await expect(dataRow).toContainText(/mental status change/i); + await expect(dataRow).toContainText(/feeling faint and light-headed/i); + }); + + await test.step('When I click the overflow menu in the table row with the newly added allergy', async () => { + await page + .getByRole('button', { name: /options/i }) + .nth(0) + .click(); + }); + + await test.step('And I click on the `Edit` button', async () => { + await page.getByRole('menuitem', { name: /edit/i }).click(); + }); + + await test.step('Then I should see the allergy form launch in the workspace in edit mode`', async () => { + await expect(page.getByText(/edit an allergy/i)).toBeVisible(); + await expect(page.getByText(/ace inhibitors/i)).toBeVisible(); + }); + + await test.step('When I change the allergy to `Bee stings`', async () => { + await page.getByPlaceholder(/select the allergen/i).click(); + await page.getByText(/bee stings/i).click(); + }); + + await test.step('And I change the severity to `Severe`', async () => { + await page.getByText(/severe/i).click(); + }); + + await test.step('And I change the allergy comment to `Itching all over the body`', async () => { + await page.locator('#comments').clear(); + await page.locator('#comments').fill('Itching all over the body'); + }); + + await test.step('And I click on the `Save and close` button', async () => { + await page.getByRole('button', { name: /save and close/i }).click(); + }); + + await test.step('Then I should see a success toast notification', async () => { + await expect(page.getByText(/allergy updated/i)).toBeVisible(); + }); + + await test.step('And I should see the updated allergy in the list', async () => { + await expect(headerRow).toContainText(/allergen/i); + await expect(headerRow).toContainText(/severity/i); + await expect(headerRow).toContainText(/reaction/i); + await expect(headerRow).toContainText(/onset date and comments/i); + await expect(dataRow).toContainText(/bee stings/i); + await expect(dataRow).not.toContainText(/ace inhibitors/i); + await expect(dataRow).toContainText(/severe/i); + await expect(dataRow).not.toContainText(/mild/i); + await expect(dataRow).toContainText(/itching all over the body/i); + await expect(dataRow).not.toContainText(/feeling faint and light-headed/i); + }); + + await test.step('When I click the overflow menu in the table row with the updated allergy', async () => { + await page + .getByRole('button', { name: /options/i }) + .nth(0) + .click(); + }); + + await test.step('And I click on the `Delete` button', async () => { + await page.getByRole('menuitem', { name: /delete/i }).click(); + await page.getByRole('button', { name: /delete/i }).click(); + }); + + await test.step('Then I should see a success toast notification', async () => { + await expect(page.getByText(/allergy deleted/i)).toBeVisible(); + }); + + await test.step('And I should not see the deleted allergy in the list', async () => { + await expect(page.getByText(/bee stings/i)).not.toBeVisible(); + }); + + await test.step('And the allergy table should be empty', async () => { + await expect(page.getByText(/there are no allergy intolerances to display for this patient/i)).toBeVisible(); + }); +}); + +test.afterEach(async ({ api }) => { + await deletePatient(api, patient.uuid); +}); diff --git a/e2e/specs/attachments.spec.ts b/e2e/specs/attachments.spec.ts index 90885aec8d..3b73d5a49b 100644 --- a/e2e/specs/attachments.spec.ts +++ b/e2e/specs/attachments.spec.ts @@ -42,7 +42,7 @@ test('Add and remove an attachment', async ({ page }) => { }); await test.step('And I click on the `Add Attachment` button', async () => { - await page.getByRole('button', { name: /add Attachment/i }).click(); + await page.getByRole('button', { name: /add attachment/i }).click(); }); await test.step('Then I should see a success toast notification', async () => { @@ -82,7 +82,7 @@ test('Add and remove an attachment', async ({ page }) => { }); await test.step('And the attachments table should be empty', async () => { - await expect(page.getByText(/There are no attachments to display for this patient/i)).toBeVisible(); + await expect(page.getByText(/there are no attachments to display for this patient/i)).toBeVisible(); }); }); diff --git a/e2e/specs/conditions.spec.ts b/e2e/specs/conditions.spec.ts index 4fa38171c9..a7ecf95343 100644 --- a/e2e/specs/conditions.spec.ts +++ b/e2e/specs/conditions.spec.ts @@ -120,7 +120,7 @@ test('Record, edit and delete a condition', async ({ page }) => { await test.step('And I should not see the deleted condition in the list', async () => { await expect(conditionsPage.page.getByText(/mental status change/i)).not.toBeVisible(); - await expect(conditionsPage.page.getByText(/There are no conditions to display for this patient/i)).toBeVisible(); + await expect(conditionsPage.page.getByText(/there are no conditions to display for this patient/i)).toBeVisible(); }); }); diff --git a/e2e/specs/drug-orders.spec.ts b/e2e/specs/drug-orders.spec.ts index 9d19ceb7dc..18bb6b283a 100644 --- a/e2e/specs/drug-orders.spec.ts +++ b/e2e/specs/drug-orders.spec.ts @@ -206,7 +206,7 @@ test('Record, edit and discontinue a drug order', async ({ page }) => { }); await test.step('And the medications table should be empty', async () => { - await expect(page.getByText(/There are no active medications to display for this patient/i)).toBeVisible(); + await expect(page.getByText(/there are no active medications to display for this patient/i)).toBeVisible(); }); }); diff --git a/e2e/specs/lab-orders.spec.ts b/e2e/specs/lab-orders.spec.ts index bc95b74332..e9ab67444e 100644 --- a/e2e/specs/lab-orders.spec.ts +++ b/e2e/specs/lab-orders.spec.ts @@ -117,7 +117,7 @@ test('Record, edit and discontinue a lab order', async ({ page }) => { await test.step('And the encounters table should be empty', async () => { await expect( - page.getByLabel(/all encounters/i).getByText(/There are no encounters to display for this patient/i), + page.getByLabel(/all encounters/i).getByText(/there are no encounters to display for this patient/i), ).toBeVisible(); }); }); diff --git a/e2e/specs/record-allergy.spec.ts b/e2e/specs/record-allergy.spec.ts deleted file mode 100644 index 4198fb64c3..0000000000 --- a/e2e/specs/record-allergy.spec.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { expect } from '@playwright/test'; -import { generateRandomPatient, deletePatient, type Patient } from '../commands'; -import { test } from '../core'; -import { PatientAllergiesPage } from '../pages'; - -let patient: Patient; - -test.beforeEach(async ({ api }) => { - patient = await generateRandomPatient(api); -}); - -test('Record an allergy', async ({ page }) => { - const allergiesPage = new PatientAllergiesPage(page); - const headerRow = allergiesPage.allergiesTable().locator('thead > tr'); - const dataRow = allergiesPage.allergiesTable().locator('tbody > tr'); - - await test.step('When I visit the Allergies page', async () => { - await allergiesPage.goTo(patient.uuid); - }); - - await test.step('And I click on the `Record allergy intolerance` link to launch the form', async () => { - await allergiesPage.page.getByText(/record allergy intolerance/i).click(); - }); - - await test.step('Then I should see the record allergy form launch in the workspace', async () => { - await expect(page.getByText(/record a new allergy/i)).toBeVisible(); - }); - - await test.step('When I select `ACE inhibitors` as the allergy', async () => { - await allergiesPage.page.getByPlaceholder(/select the allergen/i).click(); - await allergiesPage.page.getByText(/ace inhibitors/i).click(); - }); - - await test.step('And I select `Mental status change` as the reaction', async () => { - await allergiesPage.page.getByText(/mental status change/i).click(); - }); - - await test.step('And I select `Mild` as the severity', async () => { - await allergiesPage.page.getByText(/mild/i).click(); - }); - - await test.step('And I write `Test comment` as a comment', async () => { - await allergiesPage.page.locator('#comments').fill('Test comment'); - }); - - await test.step('And I click on the `Save and close` button', async () => { - await allergiesPage.page.getByRole('button', { name: /save and close/i }).click(); - }); - - await test.step('Then I should see a success toast notification', async () => { - await expect(allergiesPage.page.getByText(/allergy saved/i)).toBeVisible(); - }); - - await test.step('And I should see the newly recorded drug allergen in the list', async () => { - await expect(headerRow).toContainText(/allergen/i); - await expect(headerRow).toContainText(/severity/i); - await expect(headerRow).toContainText(/reaction/i); - await expect(headerRow).toContainText(/onset date and comments/i); - await expect(dataRow).toContainText(/ace inhibitors/i); - await expect(dataRow).toContainText(/mild/i); - await expect(dataRow).toContainText(/mental status change/i); - await expect(dataRow).toContainText(/test comment/i); - }); -}); - -test.afterEach(async ({ api }) => { - await deletePatient(api, patient.uuid); -});