From edd2d34fb239e9e0bf6627f96f52e1d9c430ba2f Mon Sep 17 00:00:00 2001 From: kdaud Date: Fri, 16 Aug 2024 08:25:14 +0300 Subject: [PATCH 1/2] E2E tests for medications and lab orders --- .github/workflows/e2e.yml | 4 +- e2e/tests/bahmni-odoo-flows.spec.ts | 12 ++--- e2e/tests/lab-orders.spec.ts | 69 +++++++++++++++++++++++++ e2e/tests/medications.spec.ts | 80 +++++++++++++++++++++++++++++ e2e/utils/functions/bahmni.ts | 14 ++++- 5 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 e2e/tests/lab-orders.spec.ts create mode 100644 e2e/tests/medications.spec.ts diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 027a58c..669eff2 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -4,9 +4,9 @@ on: schedule: - cron: "0 0 * * *" push: - branches: [main] + branches: [master] pull_request: - branches: [main] + branches: [master] workflow_dispatch: inputs: diff --git a/e2e/tests/bahmni-odoo-flows.spec.ts b/e2e/tests/bahmni-odoo-flows.spec.ts index b12a6e0..1295daa 100644 --- a/e2e/tests/bahmni-odoo-flows.spec.ts +++ b/e2e/tests/bahmni-odoo-flows.spec.ts @@ -10,11 +10,11 @@ test.beforeEach(async ({ page }) => { odoo = new Odoo(page); await bahmni.login(); - await expect(page.getByText('Registration')).toBeVisible(); - await expect(page.getByText('Clinical')).toBeVisible(); - await expect(page.getByText('Admin')).toBeVisible(); - await expect(page.getByText('Appointment Scheduling')).toBeVisible(); - await expect(page.getByText('Patient Documents')).toBeVisible(); + await expect(page.getByText(/registration/i)).toBeVisible(); + await expect(page.getByText(/linical/i)).toBeVisible(); + await expect(page.getByText(/admin/i)).toBeVisible(); + await expect(page.getByText(/appointment scheduling/i)).toBeVisible(); + await expect(page.getByText(/patient documents/i)).toBeVisible(); }); test('Ordering a lab test for a Bahmni patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => { @@ -25,7 +25,7 @@ test('Ordering a lab test for a Bahmni patient creates the corresponding Odoo cu await bahmni.goToLabSamples(); await page.getByText('Blood', { exact: true }).click(); await page.getByText('Malaria').click(); - await bahmni.saveLabOrder(); + await bahmni.saveOrder(); // verify await odoo.open(); diff --git a/e2e/tests/lab-orders.spec.ts b/e2e/tests/lab-orders.spec.ts new file mode 100644 index 0000000..6b47e6d --- /dev/null +++ b/e2e/tests/lab-orders.spec.ts @@ -0,0 +1,69 @@ +import { test, expect } from '@playwright/test'; +import { Bahmni } from '../utils/functions/bahmni'; + +let bahmni: Bahmni; + +test.beforeEach(async ({ page }) => { + bahmni = new Bahmni(page); + + await bahmni.login(); + await expect(page.getByText(/registration/i)).toBeVisible(); + await expect(page.getByText(/linical/i)).toBeVisible(); + await expect(page.getByText(/admin/i)).toBeVisible(); + await expect(page.getByText(/appointment scheduling/i)).toBeVisible(); + await expect(page.getByText(/patient documents/i)).toBeVisible(); +}); + +test('Record, revise and discontinue lab tests.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + + // replay + await bahmni.goToLabSamples(); + await page.getByText('Blood', { exact: true }).click(); + await page.getByText('Malaria').click(); + await page.getByText('Urine').click(); + await page.getByText('Gravindex').click(); + await page.getByText('Stool').click(); + await page.getByText('Stool Colour').click(); + await page.getByText('Vaginal Swab').click(); + await page.getByText('Bacteries').click(); + await page.getByText('Sputum').click(); + await page.getByText('Serial sputum bacilloscopy').click(); + await bahmni.saveOrder(); + + // verify + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Gravindex')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Stool Colour')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Bacteria')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Serial sputum bacilloscopy')).toBeVisible(); + + await page.locator('#view-content :nth-child(1).btn--success').click(); + await page.getByText('Orders', { exact: true }).click(); + await page.getByText('Blood', { exact: true }).click(); + await page.locator('#selected-orders li').filter({ hasText: 'Malaria' }).locator('i').nth(1).click(); + await page.getByText('Blood Sugar').click(); + await page.getByText('Urine').click(); + await page.locator('#selected-orders li').filter({ hasText: 'Gravindex' }).locator('i').nth(1).click(); + await page.getByText('Urine Colour').click(); + await page.getByText('Stool', { exact: true }).click(); + await page.getByText('Stool Parasites').click(); + await bahmni.saveOrder(); + + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')).not.toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Blood Sugar')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Gravindex')).not.toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Urine Colour')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Stool Colour')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Stool Parasites')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Bacteria')).toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Serial sputum bacilloscopy')).toBeVisible(); +}); + +test.afterEach(async ({ page }) => { + await bahmni.voidPatient(); + await page.close(); +}); diff --git a/e2e/tests/medications.spec.ts b/e2e/tests/medications.spec.ts new file mode 100644 index 0000000..4ba0127 --- /dev/null +++ b/e2e/tests/medications.spec.ts @@ -0,0 +1,80 @@ +import { test, expect } from '@playwright/test'; +import { Bahmni } from '../utils/functions/bahmni'; + +let bahmni: Bahmni; + +test.beforeEach(async ({ page }) => { + bahmni = new Bahmni(page); + + await bahmni.login(); + await expect(page.getByText(/registration/i)).toBeVisible(); + await expect(page.getByText(/linical/i)).toBeVisible(); + await expect(page.getByText(/admin/i)).toBeVisible(); + await expect(page.getByText(/appointment scheduling/i)).toBeVisible(); + await expect(page.getByText(/patient documents/i)).toBeVisible(); +}); + +test('Record, revise and discontinue a drug order.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + + // replay + await bahmni.goToMedications(); + await page.locator('#drug-name').type('Aspirine Co 81mg'); + await page.getByText('Aspirine Co 81mg (Comprime)').click(); + await page.locator('#uniform-dose').fill('2'); + await page.locator('#uniform-dose-unit').selectOption('string:Application(s)'); + await page.locator('#frequency').selectOption('string:Q3H'); + await page.locator('#route').selectOption('string:Topique'); + await page.locator('#start-date').fill('2024-08-16'); + await page.locator('#duration').fill('5'); + await page.locator('#duration-unit').selectOption('string:Semaine(s)'); + await page.locator('#total-quantity-unit').selectOption('string:Ampoule(s)'); + await page.locator('#instructions').selectOption('string:Estomac vide'); + await page.locator('#additional-instructions').fill('Take after a meal'); + await page.getByRole('button', { name: 'Add' }).click(); + await bahmni.saveOrder(); + + // verify + await page.locator('#dashboard-link span.patient-name').click(); + const drugNameSelector = await page.locator('treatment-table td.drug.active-drug span'); + const medicationDetailsSelector = await page.locator('#dashboard-treatments td.dosage span:nth-child(1)'); + await expect(drugNameSelector).toHaveText('Aspirine Co 81mg (Comprime)'); + await expect(medicationDetailsSelector).toContainText('2 Application(s)'); + await expect(medicationDetailsSelector).toContainText('Q3H'); + await expect(medicationDetailsSelector).toContainText('Estomac vide'); + await expect(medicationDetailsSelector).toContainText('Topique'); + + await page.locator('#view-content :nth-child(1).btn--success').click(); + await page.getByText('Medications', { exact: true }).click(); + await page.locator('#ordered-drug-orders button:nth-child(1) i').first().click(); + await page.locator('#uniform-dose').clear(); + await page.locator('#uniform-dose').fill('4'); + await page.locator('#frequency').selectOption('string:Q4H'); + await page.locator('#uniform-dose-unit').selectOption('string:Comprime(s)'); + await page.locator('#route').selectOption('string:Inhalation'); + await page.getByRole('button', { name: 'Add' }).click(); + await bahmni.saveOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(medicationDetailsSelector).not.toContainText('2 Application(s)'); + await expect(medicationDetailsSelector).toContainText('4 Comprime(s)'); + await expect(medicationDetailsSelector).not.toContainText('Q3H'); + await expect(medicationDetailsSelector).toContainText('Q4H,'); + await expect(medicationDetailsSelector).not.toContainText('Ampoule(s)'); + await expect(medicationDetailsSelector).toContainText('Inhalation'); + + await page.locator('#view-content :nth-child(1).btn--success').click(); + await page.getByText('Medications', { exact: true }).click(); + const drugSelector = await page.locator('strong.drug-name').first(); + await expect(drugSelector).toContainText('Aspirine Co 81mg (Comprime)'); + await page.getByRole('button', { name: 'Stop' }).first().click(); + await page.getByPlaceholder('Notes').clear(); + await page.getByPlaceholder('Notes').fill('Patient allergic to medicine'); + await bahmni.saveOrder(); + await expect(page.getByText(/no recent treatments/i)).toBeVisible(); +}); + +test.afterEach(async ({ page }) => { + await bahmni.voidPatient(); + await page.close(); +}); diff --git a/e2e/utils/functions/bahmni.ts b/e2e/utils/functions/bahmni.ts index ffdf226..ede1c3f 100644 --- a/e2e/utils/functions/bahmni.ts +++ b/e2e/utils/functions/bahmni.ts @@ -60,8 +60,18 @@ export class Bahmni { await expect(this.page.getByText('Lab Samples')).toBeVisible(); } - async saveLabOrder() { + async goToMedications() { + await this.page.locator('i.fa.fa-home').click(); + await this.page.getByRole('link', { name: 'Clinical' }).click(); + await this.searchPatient(); + await this.page.locator('#view-content :nth-child(1).btn--success').click(); + await this.page.getByText('Medications', { exact: true }).click(); + await expect(this.page.getByText('Order Drug')).toBeVisible(); + await expect(this.page.getByText('Order an Order Set')).toBeVisible(); + } + + async saveOrder() { await this.page.getByRole('button', { name: 'Save' }).click(); - await expect(this.page.getByText('Saved')).toBeVisible(); + await expect(this.page.getByText('Saved', {exact: true})).toBeVisible(); } } From 71a5bbef27d7fb7888546e302f85dec735095178 Mon Sep 17 00:00:00 2001 From: kdaud Date: Tue, 20 Aug 2024 11:17:27 +0300 Subject: [PATCH 2/2] Address reviews --- e2e/tests/lab-orders.spec.ts | 18 ++++++++++++++++-- e2e/tests/medications.spec.ts | 25 +++++++++++++------------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/e2e/tests/lab-orders.spec.ts b/e2e/tests/lab-orders.spec.ts index 6b47e6d..32897d5 100644 --- a/e2e/tests/lab-orders.spec.ts +++ b/e2e/tests/lab-orders.spec.ts @@ -14,7 +14,7 @@ test.beforeEach(async ({ page }) => { await expect(page.getByText(/patient documents/i)).toBeVisible(); }); -test('Record, revise and discontinue lab tests.', async ({ page }) => { +test('Create, revise and discontinue lab tests.', async ({ page }) => { // setup await bahmni.registerPatient(); @@ -32,7 +32,7 @@ test('Record, revise and discontinue lab tests.', async ({ page }) => { await page.getByText('Serial sputum bacilloscopy').click(); await bahmni.saveOrder(); - // verify + // verify creation await page.locator('#dashboard-link span.patient-name').click(); await expect(page.locator('#Lab-Orders').getByText('Malaria')).toBeVisible(); await expect(page.locator('#Lab-Orders').getByText('Gravindex')).toBeVisible(); @@ -40,6 +40,7 @@ test('Record, revise and discontinue lab tests.', async ({ page }) => { await expect(page.locator('#Lab-Orders').getByText('Bacteria')).toBeVisible(); await expect(page.locator('#Lab-Orders').getByText('Serial sputum bacilloscopy')).toBeVisible(); + // verify revision await page.locator('#view-content :nth-child(1).btn--success').click(); await page.getByText('Orders', { exact: true }).click(); await page.getByText('Blood', { exact: true }).click(); @@ -52,6 +53,7 @@ test('Record, revise and discontinue lab tests.', async ({ page }) => { await page.getByText('Stool Parasites').click(); await bahmni.saveOrder(); + // verify revision await page.locator('#dashboard-link span.patient-name').click(); await expect(page.locator('#Lab-Orders').getByText('Malaria')).not.toBeVisible(); await expect(page.locator('#Lab-Orders').getByText('Blood Sugar')).toBeVisible(); @@ -61,6 +63,18 @@ test('Record, revise and discontinue lab tests.', async ({ page }) => { await expect(page.locator('#Lab-Orders').getByText('Stool Parasites')).toBeVisible(); await expect(page.locator('#Lab-Orders').getByText('Bacteria')).toBeVisible(); await expect(page.locator('#Lab-Orders').getByText('Serial sputum bacilloscopy')).toBeVisible(); + + // verify cancellation + await page.locator('#view-content :nth-child(1).btn--success').click(); + await page.getByText('Orders', { exact: true }).click(); + await page.locator('#selected-orders li').filter({ hasText: 'Blood Sugar' }).locator('i').nth(1).click(); + await page.locator('#selected-orders li').filter({ hasText: 'Urine Colour' }).locator('i').nth(1).click(); + await page.locator('#selected-orders li').filter({ hasText: 'Stool Colour' }).locator('i').nth(1).click(); + await bahmni.saveOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Blood Sugar')).not.toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Urine Colour')).not.toBeVisible(); + await expect(page.locator('#Lab-Orders').getByText('Stool Colour')).not.toBeVisible(); }); test.afterEach(async ({ page }) => { diff --git a/e2e/tests/medications.spec.ts b/e2e/tests/medications.spec.ts index 4ba0127..fa3bd11 100644 --- a/e2e/tests/medications.spec.ts +++ b/e2e/tests/medications.spec.ts @@ -14,7 +14,7 @@ test.beforeEach(async ({ page }) => { await expect(page.getByText(/patient documents/i)).toBeVisible(); }); -test('Record, revise and discontinue a drug order.', async ({ page }) => { +test('Create, revise and discontinue a drug order.', async ({ page }) => { // setup await bahmni.registerPatient(); @@ -35,16 +35,19 @@ test('Record, revise and discontinue a drug order.', async ({ page }) => { await page.getByRole('button', { name: 'Add' }).click(); await bahmni.saveOrder(); - // verify - await page.locator('#dashboard-link span.patient-name').click(); - const drugNameSelector = await page.locator('treatment-table td.drug.active-drug span'); - const medicationDetailsSelector = await page.locator('#dashboard-treatments td.dosage span:nth-child(1)'); + // verify creation + const drugNameSelector = await page.locator('#ordered-drug-orders strong.drug-name').first(); + const medicationDetailsSelector = await page.locator('#ordered-drug-orders div.drug-details').first(); await expect(drugNameSelector).toHaveText('Aspirine Co 81mg (Comprime)'); await expect(medicationDetailsSelector).toContainText('2 Application(s)'); await expect(medicationDetailsSelector).toContainText('Q3H'); await expect(medicationDetailsSelector).toContainText('Estomac vide'); await expect(medicationDetailsSelector).toContainText('Topique'); + await page.locator('#dashboard-link span.patient-name').click(); + const medicationSelector = await page.locator('treatment-table td.drug.active-drug span'); + await expect(medicationSelector).toHaveText('Aspirine Co 81mg (Comprime)'); + // verify revision await page.locator('#view-content :nth-child(1).btn--success').click(); await page.getByText('Medications', { exact: true }).click(); await page.locator('#ordered-drug-orders button:nth-child(1) i').first().click(); @@ -55,7 +58,6 @@ test('Record, revise and discontinue a drug order.', async ({ page }) => { await page.locator('#route').selectOption('string:Inhalation'); await page.getByRole('button', { name: 'Add' }).click(); await bahmni.saveOrder(); - await page.locator('#dashboard-link span.patient-name').click(); await expect(medicationDetailsSelector).not.toContainText('2 Application(s)'); await expect(medicationDetailsSelector).toContainText('4 Comprime(s)'); await expect(medicationDetailsSelector).not.toContainText('Q3H'); @@ -63,15 +65,14 @@ test('Record, revise and discontinue a drug order.', async ({ page }) => { await expect(medicationDetailsSelector).not.toContainText('Ampoule(s)'); await expect(medicationDetailsSelector).toContainText('Inhalation'); - await page.locator('#view-content :nth-child(1).btn--success').click(); - await page.getByText('Medications', { exact: true }).click(); - const drugSelector = await page.locator('strong.drug-name').first(); - await expect(drugSelector).toContainText('Aspirine Co 81mg (Comprime)'); + // verify cancellation + await expect(drugNameSelector).toContainText('Aspirine Co 81mg (Comprime)'); await page.getByRole('button', { name: 'Stop' }).first().click(); - await page.getByPlaceholder('Notes').clear(); await page.getByPlaceholder('Notes').fill('Patient allergic to medicine'); await bahmni.saveOrder(); - await expect(page.getByText(/no recent treatments/i)).toBeVisible(); + await page.locator('#dashboard-link span.patient-name').click(); + const medicationStatus = await page.locator('#dashboard-treatments span.discontinued-text').first(); + await expect(medicationStatus).toContainText('Stopped'); }); test.afterEach(async ({ page }) => {