Skip to content

Commit

Permalink
(test) Refactor lab orders E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen committed Apr 19, 2024
1 parent 3a5fdb1 commit 8bcf22a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 87 deletions.
1 change: 1 addition & 0 deletions e2e/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 11 additions & 0 deletions e2e/pages/orders-page.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
}
1 change: 0 additions & 1 deletion e2e/specs/clinical-forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
113 changes: 27 additions & 86 deletions e2e/specs/lab-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 }).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();
});
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ title, patientUuid, sh
<div ref={contentToPrintRef}>
<PrintComponent subheader={title} patientDetails={patientDetails} />
<DataTable
aria-label={t('orderDetails', 'Order details')}
data-floating-menu-container
size="sm"
headers={tableHeaders}
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-orders-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"orderBasketWorkspaceTitle": "Order Basket",
"orderCancellation": "Order cancellation",
"orderCancelled": "Order cancelled",
"orderDetails": "Order details",
"orderedBy": "Ordered By",
"ordererInformation": "Orderer information",
"orderNumber": "Order number",
Expand Down

0 comments on commit 8bcf22a

Please sign in to comment.