From 76177b9343271ffe9221a7afd1ae32ed5f5f6136 Mon Sep 17 00:00:00 2001 From: kdaud Date: Mon, 4 Nov 2024 16:39:17 +0300 Subject: [PATCH] OZ-541: E2E test verifying discontinuing a synced OpenMRS lab order for an ERPNext customer removes the corresponding quotation. --- e2e/tests/erpnext-openmrs-flows.spec.ts | 28 ++++++++++++++++++++++--- e2e/utils/functions/erpnext.ts | 9 ++++++-- e2e/utils/functions/openmrs.ts | 20 +++++++----------- package.json | 2 +- playwright.config.ts | 2 +- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/e2e/tests/erpnext-openmrs-flows.spec.ts b/e2e/tests/erpnext-openmrs-flows.spec.ts index 5b70af6..adef1e4 100644 --- a/e2e/tests/erpnext-openmrs-flows.spec.ts +++ b/e2e/tests/erpnext-openmrs-flows.spec.ts @@ -138,7 +138,6 @@ test('Revising details of a synced OpenMRS drug order modifies the corresponding await erpnext.searchQuotation(); await page.getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); await expect(page.locator('div.bold:nth-child(4) div:nth-child(2) div')).toHaveText('8'); - await erpnext.voidQuotation(); await openmrs.voidPatient(); await erpnext.deleteQuotation(); }); @@ -155,7 +154,7 @@ test('Ordering a drug with a free text medication dosage for an OpenMRS patient await page.locator('#customer-dashboard_tab-tab').click(); await page.getByLabel('Dashboard').getByText('Quotation').click(); await erpnext.searchQuotation(); - await expect(page.getByText('Draft').nth(0)).toBeVisible(); + await expect(page.locator('div.list-row-container:nth-child(3) div:nth-child(3) span:nth-child(1) span').nth(1)).toHaveText('Draft'); await openmrs.voidPatient(); await erpnext.deleteQuotation(); }); @@ -183,6 +182,29 @@ test('Discontinuing a synced OpenMRS drug order for an ERPNext customer with a s await openmrs.voidPatient(); }); +test('Discontinuing a synced OpenMRS lab order for an ERPNext customer removes the corresponding quotation.', async ({ page }) => { + // setup + await openmrs.navigateToLabOrderForm(); + await page.getByPlaceholder('Search for a test type').fill('Complete blood count'); + await openmrs.saveLabOrder(); + + await erpnext.open(); + await erpnext.searchQuotation(); + await expect(page.getByText(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeVisible(); + + // replay + await page.goto(`${O3_URL}`); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.cancelLabOrder(); + + // verify + await page.goto(`${ERPNEXT_URL}/app/home`); + await erpnext.searchQuotation(); + await expect(page.getByText(`${patientName.firstName + ' ' + patientName.givenName}`)).not.toBeVisible(); + await expect(page.getByText('No Quotation found')).toBeVisible(); + await openmrs.voidPatient(); +}); +/* test('Ordering a drug for an OpenMRS patient within a visit creates the corresponding ERPNext customer with a filled quotation linked to the visit.', async ({ page }) => { // setup await openmrs.navigateToDrugOrderForm(); @@ -212,7 +234,7 @@ test('Ordering a drug for an OpenMRS patient within a visit creates the correspo await openmrs.voidPatient(); await erpnext.deleteQuotation(); }); - +*/ test.afterEach(async ({ page }) => { await erpnext.deleteCustomer(); await openmrs.logout(); diff --git a/e2e/utils/functions/erpnext.ts b/e2e/utils/functions/erpnext.ts index a5d46f5..9c96525 100644 --- a/e2e/utils/functions/erpnext.ts +++ b/e2e/utils/functions/erpnext.ts @@ -16,18 +16,20 @@ export class ERPNext { async searchCustomer() { await this.page.getByRole('link', { name: /selling/i }).click(); await this.page.getByRole('link', { name: 'Customer', exact: true }).click(); + await expect(this.page.getByPlaceholder('Customer Name')).toBeVisible(); await this.page.getByPlaceholder('Customer Name').clear(); await this.page.getByPlaceholder('Customer Name').fill(`${patientName.givenName}`); - await delay(5000); + await delay(3500); } async searchQuotation() { await this.page.getByRole('link', { name: /selling/i }).click(); await this.page.getByRole('link', { name: 'Quotation', exact: true }).click(); + await expect(this.page.getByPlaceholder(/title/i)).toBeVisible(); await this.page.getByPlaceholder(/title/i).clear(); await this.page.getByPlaceholder(/party/i).clear(); await this.page.getByPlaceholder(/title/i).fill(`${patientName.givenName}`); - await delay(5000); + await delay(3500); } async deleteQuotation() { @@ -36,6 +38,7 @@ export class ERPNext { await this.page.getByRole('checkbox', { name: 'Select All' }).check(); await delay(2000); await this.page.getByRole('button', { name: 'Actions' }).click(); + await expect(this.page.getByRole('link', { name: 'Delete' })).toBeVisible(); await this.page.getByRole('link', { name: 'Delete' }).click(); await this.page.getByRole('button', { name: 'Yes' }).click(); await expect(this.page.getByText('No Quotation found')).toBeVisible(); @@ -47,6 +50,7 @@ export class ERPNext { await this.page.getByRole('checkbox', { name: 'Select All' }).check(); await delay(2000); await this.page.getByRole('button', { name: 'Actions' }).click(); + await expect(this.page.getByRole('link', { name: 'Cancel' })).toBeVisible(); await this.page.getByRole('link', { name: 'Cancel' }).click(); await this.page.getByRole('button', { name: 'Yes' }).click(); } @@ -57,6 +61,7 @@ export class ERPNext { await this.page.getByRole('checkbox', { name: 'Select All' }).check(); await delay(2000); await this.page.getByRole('button', { name: 'Actions' }).click(); + await expect(this.page.getByRole('link', { name: 'Delete' })).toBeVisible(); await this.page.getByRole('link', { name: 'Delete' }).click(); await this.page.getByRole('button', { name: 'Yes' }).click(); await expect(this.page.getByText('No Customer found')).toBeVisible(); diff --git a/e2e/utils/functions/openmrs.ts b/e2e/utils/functions/openmrs.ts index ebc6d58..eb0c276 100644 --- a/e2e/utils/functions/openmrs.ts +++ b/e2e/utils/functions/openmrs.ts @@ -71,20 +71,12 @@ export class OpenMRS { await this.page.getByLabel('Family Name').fill(`${patientName.givenName}`); await this.page.locator('label').filter({ hasText: /^Male$/ }).locator('span').first().click(); await this.page.locator('div').filter({ hasText: /^Date of Birth Known\?YesNo$/ }).getByRole('tab', { name: 'No' }).click(); + await expect(this.page.getByLabel('Estimated age in years')).toBeVisible(); await this.page.getByLabel('Estimated age in years').clear(); await this.page.getByLabel('Estimated age in years').fill(`${Math.floor(Math.random() * 99)}`); await expect(this.page.getByText('Register Patient')).toBeVisible(); - if (await this.page.getByTitle('close notification').isVisible()) { - await this.page.getByTitle('close notification').click(); - } await this.page.getByRole('button', { name: 'Register Patient' }).click(); await expect(this.page.getByText('New Patient Created')).toBeVisible(); - if (await this.page.getByTitle('close notification').first().isVisible()) { - await this.page.getByTitle('close notification').first().click(); - } - if (await this.page.getByTitle('close notification').isVisible()) { - await this.page.getByTitle('close notification').click(); - } await this.page.getByRole('button', { name: 'Close', exact: true }).click(); await delay(3000); } @@ -141,7 +133,7 @@ export class OpenMRS { await this.page.locator('label').filter({ hasText: 'Facility Visit' }).locator('span').first().click(); await this.page.locator('form').getByRole('button', { name: 'Start visit' }).click(); await expect(this.page.getByText('Facility Visit started successfully')).toBeVisible(); - await delay(5000); + await delay(4000); } async endPatientVisit() { @@ -150,7 +142,7 @@ export class OpenMRS { await this.page.getByRole('menuitem', { name: 'End visit' }).click(); await this.page.getByRole('button', { name: 'danger End Visit' }).click(); await expect(this.page.getByText('Visit ended')).toBeVisible(); - await this.page.getByRole('button', { name: 'Close', exact: true }).click(); + await delay(3000); } async voidPatient() { @@ -232,12 +224,12 @@ export class OpenMRS { } async saveLabOrder() { - await delay(3000); + await delay(2500); await this.page.getByRole('button', { name: 'Order form' }).click(); await this.page.getByRole('button', { name: 'Save order' }).click(); await this.page.getByRole('button', { name: 'Sign and close' }).click(); await expect(this.page.getByText('Placed orders')).toBeVisible(); - await delay(3000); + await delay(5000); } async voidEncounter() { @@ -255,7 +247,9 @@ export class OpenMRS { await this.page.getByRole('link', { name: 'Orders' }).click(); await this.page.getByRole('button', { name: 'Options' }).nth(0).click(); await this.page.getByRole('menuitem', { name: 'Cancel Order' }).click(); + await expect(this.page.getByRole('button', { name: 'Sign and close' })).toBeEnabled(); await this.page.getByRole('button', { name: 'Sign and close' }).click(); + await delay(3000); } async viewTestResults() { diff --git a/package.json b/package.json index 7c98608..d702b36 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "!playwright-report/" ], "scripts": { - "ozone-pro": "npx playwright test", + "ozone-pro": "npx playwright test erpnext", "ozone-foss": "npx playwright test odoo-openmrs erpnext-openmrs openmrs-senaite", "openmrs-distro-his": "npx playwright test odoo-openmrs openmrs-senaite" }, diff --git a/playwright.config.ts b/playwright.config.ts index d4222e6..4f12fd4 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -24,7 +24,7 @@ const config: PlaywrightTestConfig = { name: 'chromium', use: { ...devices['Desktop Chromium'], - viewport: { width: 1920, height: 1080 } + viewport: { width: 1920, height: 1080 }, }, },