Skip to content

Commit

Permalink
OZ-541: E2E tests for flows between ERPNext and OpenMRS (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud authored Jul 19, 2024
1 parent bbc11a0 commit 78116e4
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ O3_URL_DEMO=https://demo.ozone-his.com

# ERPNEXT
ERPNEXT_URL_DEV=https://erpnext.ozone-dev.mekomsolutions.net
ERPNEXT_URL_QA=
ERPNEXT_URL_DEMO=
ERPNEXT_URL_QA=https://erpnext.ozone-qa.mekomsolutions.net
ERPNEXT_URL_DEMO=https://erpnext.demo.ozone-his.com

# Odoo
ODOO_URL_DEV=https://erp.ozone-dev.mekomsolutions.net
Expand Down
115 changes: 105 additions & 10 deletions e2e/tests/erpnext-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,92 @@ test('Ordering a lab test for an OpenMRS patient creates the corresponding ERPNe
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchCustomer();
const customer = await page.locator(".bold a:nth-child(1)");
const customer = await page.locator("div.list-row-container:nth-child(3) span:nth-child(2) a");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});

test('Ordering a drug for an OpenMRS patient creates the corresponding ERPNext customer with a filled quotation.', async ({ page }) => {
// replay
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();

// verify
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchCustomer();
const customer = await page.locator(".bold a:nth-child(1)");
const customer = await page.locator("div.list-row-container:nth-child(3) span:nth-child(2) a");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);
await page.getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click();
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();
const quotationStatus = await page.locator('div.list-row-container:nth-child(3) div:nth-child(3) span:nth-child(1) span').nth(1);
await expect(quotationStatus).toHaveText('Draft');
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});

test('Editing the details of an OpenMRS patient with a synced lab order edits the corresponding ERPNext customer details.', async ({ page }) => {
// setup
await openmrs.goToLabOrderForm();
await page.getByPlaceholder('Search for a test type').fill('Blood urea nitrogen');
await openmrs.saveLabOrder();
await erpnext.open();
await erpnext.searchCustomer();
const customer = await page.locator("div.list-row-container:nth-child(3) span:nth-child(2) a");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);

// replay
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.updatePatientDetails();

// verify
await page.goto(`${ERPNEXT_URL}/app/home`);
await erpnext.searchCustomer();
await expect(customer).toContainText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName}`);
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});

test('Editing the details of an OpenMRS patient with a synced drug order edits the corresponding ERPNext customer details.', async ({ page }) => {
// setup
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await erpnext.open();
await erpnext.searchCustomer();
const customer = await page.locator("div.list-row-container:nth-child(3) span:nth-child(2) a");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);

// replay
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.updatePatientDetails();

// verify
await page.goto(`${ERPNEXT_URL}/app/home`);
await erpnext.searchCustomer();
await expect(customer).toContainText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName}`);
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});

test('Ending an OpenMRS patient visit with a synced drug order updates the corresponding ERPNext draft quotation to an open state.', async ({ page }) => {
// setup
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchQuotation();

const quotationStatus = await page.locator('div.level-left.ellipsis div:nth-child(3) span span');
const quotationStatus = await page.locator('div.list-row-container:nth-child(3) div:nth-child(3) span:nth-child(1) span');
await expect(quotationStatus).toHaveText('Draft');

// replay
Expand All @@ -76,7 +130,10 @@ test('Ending an OpenMRS patient visit with a synced drug order updates the corre

test('Revising a synced OpenMRS drug order edits the corresponding ERPNext quotation item.', async ({ page }) => {
// setup
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchQuotation();
Expand All @@ -94,6 +151,7 @@ test('Revising a synced OpenMRS drug order edits the corresponding ERPNext quota
await erpnext.searchQuotation();
await page.getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click();
await expect(quantity).toHaveText('8');
await erpnext.voidQuotation();
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});
Expand All @@ -106,7 +164,7 @@ test('Ordering a drug with a free text medication dosage for an OpenMRS patient
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchCustomer();
const customer = await page.locator(".bold a:nth-child(1)");
const customer = await page.locator("div.list-row-container:nth-child(3) span:nth-child(2) a");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);
await page.getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click();
await page.locator('#customer-dashboard_tab-tab').click();
Expand All @@ -119,7 +177,10 @@ test('Ordering a drug with a free text medication dosage for an OpenMRS patient

test('Discontinuing a synced OpenMRS drug order for an ERPNext customer with a single quotation line removes the corresponding quotation.', async ({ page }) => {
// setup
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await erpnext.open();
await expect(page).toHaveURL(/.*home/);
await erpnext.searchQuotation();
Expand All @@ -138,6 +199,40 @@ test('Discontinuing a synced OpenMRS drug order for an ERPNext customer with a s
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.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await erpnext.open();
await erpnext.searchQuotation();

const firstQuotationStatus = await page.locator('div.list-row-container:nth-child(3) div:nth-child(3) span:nth-child(1) span');
await expect(firstQuotationStatus).toHaveText('Draft');

// replay
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.endPatientVisit();
await openmrs.startPatientVisit();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 81mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();

// verify
await page.goto(`${ERPNEXT_URL}/app/home`);
await erpnext.searchQuotation();

const secondQuotationStatus = await page.locator('div.list-row-container:nth-child(4) div:nth-child(3) span:nth-child(1) span');
await expect(firstQuotationStatus).toHaveText('Draft');
await expect(secondQuotationStatus).toHaveText('Open');
await erpnext.voidQuotation();
await openmrs.voidPatient();
await erpnext.deleteQuotation();
});

test.afterEach(async ({ page }) => {
await erpnext.deleteCustomer();
await page.close();
Expand Down
42 changes: 29 additions & 13 deletions e2e/tests/odoo-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('Ordering a lab test for an OpenMRS patient creates the corresponding Odoo
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();

const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent();
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span").textContent();
await expect(quotation?.includes("Quotation")).toBeTruthy();
});

Expand All @@ -43,7 +43,7 @@ test('Editing the details of an OpenMRS patient with a synced lab order edits th
await odoo.searchCustomer();
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent();
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span").textContent();
await expect(quotation?.includes("Quotation")).toBeTruthy();
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
Expand All @@ -59,7 +59,10 @@ test('Editing the details of an OpenMRS patient with a synced lab order edits th

test('Ordering a drug for an OpenMRS patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => {
// replay
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();

// verify
await odoo.open();
Expand All @@ -68,19 +71,22 @@ test('Ordering a drug for an OpenMRS patient creates the corresponding Odoo cust
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();

const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent();
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span").textContent();
await expect(quotation?.includes("Quotation")).toBeTruthy();
});

test('Editing the details of an OpenMRS patient with a synced drug order edits the corresponding Odoo customer details.', async ({ page }) => {
// replay
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent();
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span").textContent();
await expect(quotation?.includes("Quotation")).toBeTruthy();
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
Expand All @@ -97,7 +103,10 @@ test('Editing the details of an OpenMRS patient with a synced drug order edits t

test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotation line.', async ({ page }) => {
// replay
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
Expand All @@ -121,13 +130,16 @@ test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotatio

test('Discontinuing a synced OpenMRS drug order for an Odoo customer with a single quotation line removes the corresponding quotation.', async ({ page }) => {
// replay
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)");
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(quotation).toHaveText('Quotation');
await page.getByRole('cell', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click();
const drugOrderItem = await page.locator("table tbody td.o_data_cell:nth-child(2) span:nth-child(1) span");
Expand All @@ -152,13 +164,16 @@ test('Discontinuing a synced OpenMRS drug order for an Odoo customer with multip
await page.getByPlaceholder('Search for a test type').fill('Blood urea nitrogen');
await openmrs.saveLabOrder();
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.createDrugOrder();
await openmrs.goToDrugOrderForm();
await page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
await openmrs.fillDrugOrderForm();
await openmrs.saveDrugOrder();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)");
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(quotation).toHaveText('Quotation');
await page.getByRole('cell', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click();
const labOrderItem = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(2) span:nth-child(1) span");
Expand Down Expand Up @@ -190,7 +205,7 @@ test('Ordering a drug with a free text medication dosage for an OpenMRS patient
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();

const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent();
const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span").textContent();
await expect(quotation?.includes("Quotation")).toBeTruthy();
});

Expand All @@ -204,7 +219,8 @@ test('Discontinuing a synced OpenMRS lab order for an Odoo customer with a singl
await odoo.searchCustomer();
const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent();
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)");

const quotation = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(quotation).toHaveText('Quotation');

await page.goto(`${O3_URL}`);
Expand Down
11 changes: 8 additions & 3 deletions e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ export class OpenMRS {
await this.page.getByRole('tab', { name: 'Panel' }).click();
}

async createDrugOrder() {
async goToDrugOrderForm() {
await this.page.getByLabel('Order basket', { exact: true }).click();
await this.page.getByRole('button', { name: 'Add', exact: true }).nth(0).click();
await this.page.getByPlaceholder('Search for a drug or orderset (e.g. "Aspirin")').fill('Aspirin 325mg');
}

async fillDrugOrderForm() {
await this.page.getByRole('button', { name: 'Order form' }).click();
await delay(2000);
await this.page.getByPlaceholder('Dose').fill('4');
Expand All @@ -284,13 +286,16 @@ export class OpenMRS {
await this.page.getByLabel('Quantity to dispense').fill('12');
await this.page.getByLabel('Prescription refills').fill('3');
await this.page.getByPlaceholder('e.g. "Hypertension"').type('Hypertension');
}

async saveDrugOrder() {
await this.page.getByRole('button', { name: 'Save order' }).focus();
await expect(this.page.getByText('Save order')).toBeVisible();
await this.page.getByRole('button', { name: 'Save order' }).click();
await this.page.getByRole('button', { name: 'Sign and close' }).focus();
await expect(this.page.getByText('Sign and close')).toBeVisible();
await this.page.getByRole('button', { name: 'Sign and close' }).click();
await delay(5000);
await delay(3000);
}

async createDrugOrderWithFreeTextDosage() {
Expand Down

0 comments on commit 78116e4

Please sign in to comment.