From 91745e635488c4815b8a29be8cda7de23fa3e9d7 Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Fri, 19 Apr 2024 16:57:41 +0300 Subject: [PATCH] (test) Refactor lab orders E2E test --- e2e/pages/index.ts | 1 + e2e/pages/orders-page.ts | 11 ++ e2e/specs/clinical-forms.spec.ts | 1 - e2e/specs/lab-orders.spec.ts | 113 +++++------------- ...visite-note.spec.ts => visit-note.spec.ts} | 0 .../orders-details-table.component.tsx | 1 + .../translations/en.json | 1 + 7 files changed, 41 insertions(+), 87 deletions(-) create mode 100644 e2e/pages/orders-page.ts rename e2e/specs/{visite-note.spec.ts => visit-note.spec.ts} (100%) diff --git a/e2e/pages/index.ts b/e2e/pages/index.ts index 96483d5ff8..8ebeb0db36 100644 --- a/e2e/pages/index.ts +++ b/e2e/pages/index.ts @@ -4,6 +4,7 @@ export * from './chart-page'; export * from './conditions-page'; export * from './immunizations-page'; export * from './medications-page'; +export * from './orders-page'; export * from './program-page'; export * from './results-viewer-page'; export * from './visits-page'; diff --git a/e2e/pages/orders-page.ts b/e2e/pages/orders-page.ts new file mode 100644 index 0000000000..9fb9eddaa3 --- /dev/null +++ b/e2e/pages/orders-page.ts @@ -0,0 +1,11 @@ +import { type Page } from '@playwright/test'; + +export class OrdersPage { + constructor(readonly page: Page) {} + + readonly ordersTable = () => this.page.getByRole('table', { name: /orders/i }); + + async goTo(patientUuid: string) { + await this.page.goto(`/openmrs/spa/patient/${patientUuid}/chart/Orders`); + } +} diff --git a/e2e/specs/clinical-forms.spec.ts b/e2e/specs/clinical-forms.spec.ts index 58911f6a2f..ae4e673d8e 100644 --- a/e2e/specs/clinical-forms.spec.ts +++ b/e2e/specs/clinical-forms.spec.ts @@ -37,7 +37,6 @@ test('Fill a clinical form', async ({ page }) => { await expect(headerRow).toContainText(/last completed/i); await expect(chartPage.page.getByRole('cell', { name: /covid 19/i })).toBeVisible(); - await expect(chartPage.page.getByRole('cell', { name: /laboratory test orders/i })).toBeVisible(); await expect(chartPage.page.getByRole('cell', { name: /laboratory test results/i })).toBeVisible(); await expect(chartPage.page.getByRole('cell', { name: /soap note template/i })).toBeVisible(); await expect(chartPage.page.getByRole('cell', { name: /surgical operation/i })).toBeVisible(); diff --git a/e2e/specs/lab-orders.spec.ts b/e2e/specs/lab-orders.spec.ts index daa57c4cb0..f8c9f20469 100644 --- a/e2e/specs/lab-orders.spec.ts +++ b/e2e/specs/lab-orders.spec.ts @@ -2,7 +2,7 @@ import { expect } from '@playwright/test'; import { type Visit } from '@openmrs/esm-framework'; import { generateRandomPatient, type Patient, startVisit, endVisit, deletePatient } from '../commands'; import { test } from '../core'; -import { ChartPage, VisitsPage } from '../pages'; +import { OrdersPage } from '../pages'; let patient: Patient; let visit: Visit; @@ -12,113 +12,54 @@ test.beforeEach(async ({ api }) => { visit = await startVisit(api, patient.uuid); }); -test('Record, edit and discontinue a lab order', async ({ page }) => { - const chartPage = new ChartPage(page); - const visitsPage = new VisitsPage(page); +test('Record a lab order', async ({ page }) => { + const ordersPage = new OrdersPage(page); - await test.step('When I visit the chart summary page', async () => { - await chartPage.goTo(patient.uuid); + await test.step('When I visit the orders page', async () => { + await ordersPage.goTo(patient.uuid); }); - await test.step('And I click on the `Clinical forms` button on the siderail', async () => { - await chartPage.page.getByLabel(/clinical forms/i).click(); + await test.step('And I click on the `Record orders` link', async () => { + await page.getByText(/record orders/i).click(); }); - await test.step('Then I should see the clinical forms workspace', async () => { - const headerRow = chartPage.formsTable().locator('thead > tr'); - - await expect(chartPage.page.getByPlaceholder(/search this list/i)).toBeVisible(); - await expect(headerRow).toContainText(/form name \(a-z\)/i); - await expect(headerRow).toContainText(/last completed/i); - await expect(chartPage.page.getByRole('cell', { name: /laboratory test orders/i })).toBeVisible(); - }); - - await test.step('When I launch the `Laboratory Test Orders` form', async () => { - await page.getByText(/laboratory test orders/i).click(); - }); - - await test.step('And I click on the `Add` button', async () => { - await page.getByRole('button', { name: 'Add', exact: true }).click(); - }); - - await test.step('And I set the lab test to `Blood urea nitrogen`', async () => { - await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); + await test.step('And I click the `Add +` button on the Lab orders tile', async () => { + await page.getByRole('button', { name: /add/i }).nth(1).click(); }); - 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 type `Blood urea nitrogen` into the search bar', async () => { + await page.getByRole('searchbox', { name: /search for a test type/i }).fill('blood urea nitrogen'); }); - await test.step('Then I should see a success notification', async () => { - await expect(page.getByText('Lab order(s) generated')).toBeVisible(); - await expect(page.getByText(/blood urea nitrogen/i)).toBeVisible(); - }); - - await test.step('When I navigate to the visits dashboard', async () => { - await visitsPage.goTo(patient.uuid); - }); - - await test.step('And I go to the `All encounters` tab', async () => { - await page.getByRole('tab', { name: /all encounters/i }).click(); - }); - - await test.step('Then I should see the newly added lab order in the list', async () => { - await expect( - page.getByRole('cell', { name: /laboratory test orders/i }).getByText('Laboratory Test Orders'), - ).toBeVisible(); - }); - - await test.step('When I click the overflow menu in the table row with the newly created lab order', async () => { + await test.step('And I click the `Add to basket` button on the `Blood urea nitrogen` entry in the list', async () => { await page - .getByRole('button', { name: /options/i }) - .nth(0) + .getByRole('listitem') + .filter({ hasText: /blood urea nitrogen/i }) + .getByRole('button', { name: /order form/i }) .click(); }); - await test.step('And I click on the `Edit` button', async () => { - await page.getByRole('menuitem', { name: /edit this encounter/i }).click(); - }); - - await test.step('And I change the lab test to `Hepatitis c test - qualitative`', async () => { - await page.locator('#tab select').selectOption('1325AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); + await test.step('Then I should see the lab order form launch in the workspace', async () => { + await expect(page.getByText(/add lab order/i)).toBeVisible(); }); - await test.step('And I save the form', async () => { - await page.getByRole('button', { name: /save and close/i }).click(); + await test.step('When I fill in the fields in the form for the Blood urea nitrogen test and submit the form', async () => { + await page.getByLabel(/lab reference number/i).fill(' 20240419-1234'); + await page.getByLabel(/additional instructions/i).fill(' N/A'); + await page.getByRole('button', { name: /save order/i }).click(); + await page.getByRole('button', { name: /sign and close/i }).click(); }); await test.step('Then I should see a success notification', async () => { - await expect(page.getByText('Lab order(s) generated')).toBeVisible(); - await expect(page.getByText(/blood urea nitrogen/i)).not.toBeVisible(); - await expect(page.getByText(/hepatitis c test - qualitative/i)).toBeVisible(); - }); - - await test.step('And I should see the updated Laboratory Test Order in the list', async () => { - await expect( - page.getByRole('cell', { name: /laboratory test orders/i }).getByText('Laboratory Test Orders'), - ).toBeVisible(); - }); - - await test.step('When I click the overflow menu in the table row with the updated lab order', async () => { - await page - .getByRole('button', { name: /options/i }) - .nth(0) - .click(); + await expect(page.getByText(/placed order for blood urea nitrogen/i)).toBeVisible(); }); - await test.step('And I click on the `Delete` button', async () => { - await page.getByRole('menuitem', { name: /delete this encounter/i }).click(); - await page.getByRole('button', { name: /delete/i }).click(); + await test.step('When I navigate to the orders dashboard', async () => { + await ordersPage.goTo(patient.uuid); }); - await test.step('Then I should see a success notification', async () => { - await expect(page.getByText(/encounter successfully deleted/i)).toBeVisible(); - }); - - 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), - ).toBeVisible(); + await test.step('Then I should see the newly added lab order in the list', async () => { + await expect(page.getByLabel('testorders').getByRole('cell', { name: /blood urea nitrogen/i })).toBeVisible(); }); }); diff --git a/e2e/specs/visite-note.spec.ts b/e2e/specs/visit-note.spec.ts similarity index 100% rename from e2e/specs/visite-note.spec.ts rename to e2e/specs/visit-note.spec.ts diff --git a/packages/esm-patient-orders-app/src/components/orders-details-table.component.tsx b/packages/esm-patient-orders-app/src/components/orders-details-table.component.tsx index 96054a9aff..7d14d72fd9 100644 --- a/packages/esm-patient-orders-app/src/components/orders-details-table.component.tsx +++ b/packages/esm-patient-orders-app/src/components/orders-details-table.component.tsx @@ -332,6 +332,7 @@ const OrderDetailsTable: React.FC = ({ title, patientUuid, sh