From 6108f30c720d0fe4acceb87d9afaa5c7130c116a Mon Sep 17 00:00:00 2001 From: kdaud Date: Tue, 20 Aug 2024 11:17:27 +0300 Subject: [PATCH] Address reviews --- e2e/tests/lab-orders.spec.ts | 18 ++++++++++++++++-- e2e/tests/medications.spec.ts | 23 +++++++++++------------ e2e/utils/functions/bahmni.ts | 9 +++++++++ playwright.config.ts | 4 +++- 4 files changed, 39 insertions(+), 15 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..2d04e33 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,12 +65,9 @@ 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)'); - await page.getByRole('button', { name: 'Stop' }).first().click(); - await page.getByPlaceholder('Notes').clear(); + // verify cancellation + await expect(drugNameSelector).toContainText('Aspirine Co 81mg (Comprime)'); + await page.locator('.stop-drug-btn').first().click(); await page.getByPlaceholder('Notes').fill('Patient allergic to medicine'); await bahmni.saveOrder(); await expect(page.getByText(/no recent treatments/i)).toBeVisible(); diff --git a/e2e/utils/functions/bahmni.ts b/e2e/utils/functions/bahmni.ts index ede1c3f..2963a8e 100644 --- a/e2e/utils/functions/bahmni.ts +++ b/e2e/utils/functions/bahmni.ts @@ -6,6 +6,14 @@ export var patientName = { familyName : '', } +export const delay = (mills) => { + let datetime1 = new Date().getTime(); + let datetime2 = datetime1 + mills; + while(datetime1 < datetime2) { + datetime1 = new Date().getTime(); + } +} + export class Bahmni { constructor(readonly page: Page) {} @@ -73,5 +81,6 @@ export class Bahmni { async saveOrder() { await this.page.getByRole('button', { name: 'Save' }).click(); await expect(this.page.getByText('Saved', {exact: true})).toBeVisible(); + await delay(4000) } } diff --git a/playwright.config.ts b/playwright.config.ts index e85b4da..b6f8bec 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -25,7 +25,9 @@ const config: PlaywrightTestConfig = { ...devices['Desktop Chromium'], launchOptions: { slowMo: 500 - } + }, + video: 'retain-on-failure', + screenshot: 'only-on-failure' }, },