Skip to content

Commit

Permalink
Clean up ERPNext component
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud committed May 17, 2024
1 parent c288e2a commit 54b7c44
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
7 changes: 7 additions & 0 deletions e2e/tests/erpnext-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OpenMRS, patientName } from '../utils/functions/openmrs';

let openmrs: OpenMRS;
let erpnext: ERPNext;
let quotation;

test.beforeEach(async ({ page }) => {
openmrs = new OpenMRS(page);
Expand All @@ -26,6 +27,7 @@ test('Ordering a lab test for an OpenMRS patient creates the corresponding ERPNe
await erpnext.searchCustomer();
const customer = await page.locator(".bold a:nth-child(1)");
await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);
quotation = null;
});

test('Ordering a drug for an OpenMRS patient creates the corresponding ERPNext customer with a filled quotation.', async ({ page }) => {
Expand Down Expand Up @@ -123,9 +125,14 @@ test('Discontinuing a synced OpenMRS drug order for an ERPNext customer with a s
await erpnext.searchQuotation();
await expect(page.getByText(`${patientName.firstName + ' ' + patientName.givenName}`)).not.toBeVisible();
await expect(page.getByText('No Quotation found')).toBeVisible();
quotation = null;
});

test.afterEach(async ({ page }) => {
await openmrs.deletePatient();
if (quotation !== null) {
await erpnext.deleteQuotation();
}
await erpnext.deleteCustomer();
await page.close();
});
24 changes: 23 additions & 1 deletion e2e/utils/functions/erpnext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from '@playwright/test';
import { Page, expect } from '@playwright/test';
import { delay, patientName } from './openmrs';
import { ERPNEXT_URL } from '../configs/globalSetup';

Expand Down Expand Up @@ -28,4 +28,26 @@ export class ERPNext {
await this.page.getByPlaceholder(/title/i).fill(`${patientName.givenName}`);
await delay(3000);
}

async deleteQuotation() {
await this.page.goto(`${ERPNEXT_URL}/app/quotation`);
await this.searchQuotation();
await this.page.getByRole('checkbox', { name: 'Select All' }).check();
await delay(2500);
await this.page.getByRole('button', { name: 'Actions' }).click();
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();
}

async deleteCustomer() {
await this.page.goto(`${ERPNEXT_URL}/app/customer`);
await this.searchCustomer();
await this.page.getByRole('checkbox', { name: 'Select All' }).check();
await delay(2500);
await this.page.getByRole('button', { name: 'Actions' }).click();
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();
}
}
8 changes: 3 additions & 5 deletions e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class OpenMRS {
await this.page.locator('label').filter({ hasText: 'Inpatient Ward' }).locator('span').first().click();
await this.page.getByRole('button', { name: 'Confirm' }).click();
await delay(5000);
await this.expectAllButtonsToBePresent();
await this.waitHomePageToLoad();
}

async createPatient() {
Expand All @@ -54,7 +54,7 @@ export class OpenMRS {
updatedFirstName: `${(Math.random() + 1).toString(36).substring(2)}`
}
patientFullName = patientName.firstName + ' ' + patientName.givenName;
await this.expectAllButtonsToBePresent();
await this.waitHomePageToLoad();
await this.page.getByRole('button', { name: 'Add Patient' }).click();
await expect(this.page.getByRole('button', { name: 'Register Patient' })).toBeEnabled();
await this.page.getByLabel('First Name').clear();
Expand Down Expand Up @@ -153,7 +153,6 @@ export class OpenMRS {
await this.page.getByRole('button', { name: 'Delete Patient', exact: true }).click();
const message = await this.page.locator('//*[@id="patientFormVoided"]').textContent();
await expect(message?.includes('This patient has been deleted')).toBeTruthy();
await this.page.getByRole('link', { name: 'Log out' }).click();
}

async addPatientCondition() {
Expand Down Expand Up @@ -403,10 +402,9 @@ export class OpenMRS {
await this.page.getByRole('link', { name: 'Log out' }).click();
}

async expectAllButtonsToBePresent() {
async waitHomePageToLoad() {
await expect(this.page.getByRole('button', { name: 'Search Patient' })).toBeEnabled();
await expect(this.page.getByRole('button', { name: 'Add Patient' })).toBeEnabled();
await expect(this.page.getByRole('button', { name: 'Implementer Tools' })).toBeEnabled();
await expect(this.page.getByRole('button', { name: 'My Account' })).toBeEnabled();
await expect(this.page.getByRole('button', { name: 'App Menu' })).toBeEnabled();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"!playwright-report/"
],
"scripts": {
"e2e-tests-pro": "npx playwright test",
"e2e-tests-pro": "npx playwright test erpnext-openmrs",
"e2e-tests-foss": "npx playwright test odoo-openmrs openmrs-senaite"
},
"publishConfig": {
Expand Down

0 comments on commit 54b7c44

Please sign in to comment.