Skip to content

Commit

Permalink
C2C-341: E2E tests for diagnosis workflows. (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud authored Sep 2, 2024
1 parent ec08666 commit 0703d95
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 45 deletions.
78 changes: 39 additions & 39 deletions e2e/tests/bahmni-odoo-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ test('Ordering a lab test for a Bahmni patient creates the corresponding Odoo cu
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);

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

await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName}` }).click();
const labTest = await page.locator("tr:nth-child(1) td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier");
const labTest = await page.locator('tr:nth-child(1) td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier');
await expect(labTest).toContainText('Malaria');
});

Expand All @@ -50,10 +50,10 @@ test('Editing the details of a Bahmni patient with a synced lab order edits the
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
const statusSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(statusSelector).toHaveText("Devis");
const statusSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(8) span');
await expect(statusSelector).toHaveText('Devis');

// replay
await page.goto(`${BAHMNI_URL}`);
Expand All @@ -62,9 +62,9 @@ test('Editing the details of a Bahmni patient with a synced lab order edits the
// verify
await page.goto(`${ODOO_URL}`);
await odoo.searchCustomer();
const updatedCustomer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const updatedCustomer = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(updatedCustomer).toHaveText(`${patientName.updatedGivenName}` + ' ' + `${patientName.familyName}`);
await expect(statusSelector).toHaveText("Devis");
await expect(statusSelector).toHaveText('Devis');
});

test('Revising a synced Bahmni lab order edits the corresponding Odoo quotation line.', async ({ page }) => {
Expand All @@ -74,12 +74,12 @@ test('Revising a synced Bahmni lab order edits the corresponding Odoo quotation
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
const statusSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(statusSelector).toHaveText("Devis");
const statusSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(8) span');
await expect(statusSelector).toHaveText('Devis');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName}` }).click();
const labTest = await page.locator("td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span");
const labTest = await page.locator('td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span');
await expect(labTest).toHaveText('Malaria');

// replay
Expand All @@ -91,7 +91,7 @@ test('Revising a synced Bahmni lab order edits the corresponding Odoo quotation
await page.goto(`${ODOO_URL}`);
await odoo.searchCustomer();
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
await expect(statusSelector).toHaveText("Devis");
await expect(statusSelector).toHaveText('Devis');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName }` }).first().click();
await expect(labTest).not.toContainText('Malaria');
await expect(labTest).toHaveText('Hematocrite');
Expand All @@ -104,12 +104,12 @@ test('Discontinuing a synced Bahmni lab order edits the corresponding Odoo quota
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
const statusSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(statusSelector).toHaveText("Devis");
const statusSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(8) span');
await expect(statusSelector).toHaveText('Devis');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName}` }).click();
const labTest = await page.locator("td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span");
const labTest = await page.locator('td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span');
await expect(labTest).toHaveText('Malaria');

// replay
Expand All @@ -121,40 +121,40 @@ test('Discontinuing a synced Bahmni lab order edits the corresponding Odoo quota
await page.goto(`${ODOO_URL}`);
await odoo.searchCustomer();
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
await expect(statusSelector).toHaveText("Annulé");
await expect(statusSelector).toHaveText('Annulé');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName }` }).first().click();
await expect(page.getByText('Malaria')).not.toBeVisible();
});

test('Ordering a drug for a Bahmni patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => {
// setup
await bahmni.goToMedications();
await bahmni.navigateToMedications();

// replay
await bahmni.createMedication();

// verify
await odoo.open();
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);

const statusSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(statusSelector).toHaveText("Devis");
const statusSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(8) span');
await expect(statusSelector).toHaveText('Devis');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName}` }).click();
const drugNameSelector = await page.locator("td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span");
const drugNameSelector = await page.locator('td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span');
await expect(drugNameSelector).toContainText('Aspirine Co 81mg');
});


test('Editing the details of a Bahmni patient with a synced drug order edits the corresponding Odoo customer details.', async ({ page }) => {
// setup
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.createMedication();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);

// replay
Expand All @@ -164,28 +164,28 @@ test('Editing the details of a Bahmni patient with a synced drug order edits the
// verify
await page.goto(`${ODOO_URL}`);
await odoo.searchCustomer();
const updatedCustomer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const updatedCustomer = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(updatedCustomer).toHaveText(`${patientName.updatedGivenName}` + ' ' + `${patientName.familyName}`);
});

test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotation line.', async ({ page }) => {
// setup
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.createMedication();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName }` }).click();
const medicationDescrptionSelector = await page.locator("td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier span");
const drugNameSelector = await page.locator("td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span");
const medicationDescrptionSelector = await page.locator('td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier span');
const drugNameSelector = await page.locator('td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span');
await expect(drugNameSelector).toContainText('Aspirine Co 81mg');
await expect(medicationDescrptionSelector).toContainText('Aspirine Co 81mg | 560.0 Ampoule(s) | 2.0 Application(s) - Q3H - 5 Semaine(s)');

// replay
await page.goto(`${BAHMNI_URL}`);
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.editMedicationDetails();

// verify
Expand All @@ -198,24 +198,24 @@ test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotatio

test('Discontinuing a synced Bahmni drug order for an Odoo customer with a single quotation line removes the corresponding quotation.', async ({ page }) => {
// setup
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.createMedication();
await odoo.open();
await expect(page).toHaveURL(/.*web/);
await odoo.searchCustomer();
const customerSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)");
const customerSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(4)');
await expect(customerSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`);
const statusSelector = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(8) span");
await expect(statusSelector).toHaveText("Devis");
const statusSelector = await page.locator('tr.o_data_row:nth-child(1) td:nth-child(8) span');
await expect(statusSelector).toHaveText('Devis');
await page.getByRole('cell', { name: `${patientName.givenName + ' ' + patientName.familyName }` }).click();
const medicationDescrptionSelector = await page.locator("td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier span");
const drugNameSelector = await page.locator("td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span");
const medicationDescrptionSelector = await page.locator('td.o_data_cell.o_field_cell.o_list_text.o_section_and_note_text_cell.o_required_modifier span');
const drugNameSelector = await page.locator('td.o_data_cell.o_field_cell.o_list_many2one.o_product_configurator_cell.o_required_modifier>span');
await expect(drugNameSelector).toContainText('Aspirine Co 81mg');
await expect(medicationDescrptionSelector).toContainText('Aspirine Co 81mg | 560.0 Ampoule(s) | 2.0 Application(s) - Q3H - 5 Semaine(s)');

// replay
await page.goto(`${BAHMNI_URL}`);
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.discontinueMedication();

// verify
Expand Down
54 changes: 54 additions & 0 deletions e2e/tests/diagnosis.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

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('Create and revise a diagnosis.', async ({ page }) => {
// setup
await bahmni.registerPatient();

// replay
await bahmni.navigateToDiagnosis();
await page.locator('#name-0').fill('Candidiasis (B37.9)');
await page.getByText('Candidiasis (B37.9)').click();
await page.locator('#order-0').getByRole('button', { name: /primary/i }).click();
await page.locator('#certainty-0').getByRole('button', { name: /confirmed/i }).click();
await bahmni.saveOrder();

// verify creation
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('#diagnosisName')).toContainText(/candidiasis/i);
await expect(page.locator('#order')).toContainText(/primary/i);
await expect(page.locator('#certainty')).toContainText(/confirmed/i);

// verify revision
await page.locator('#view-content :nth-child(1).btn--success').click();
await page.locator('#opd-tabs').getByText('Diagnosis').click();
await page.locator('i.fa.fa-edit').first().click();
const diagnosisOrderButton = await page.getByRole('button', { name: 'SECONDARY' }).nth(1);
await diagnosisOrderButton.waitFor({ state: 'visible' });
await diagnosisOrderButton.focus();
await diagnosisOrderButton.click();
await bahmni.saveOrder();
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('#diagnosisName')).toContainText(/candidiasis/i);
await expect(page.locator('#order')).toContainText(/secondary/i);
await expect(page.locator('#certainty')).toContainText(/confirmed/i);
});

test.afterEach(async ({ page }) => {
await bahmni.voidPatient();
await page.close();
});
2 changes: 1 addition & 1 deletion e2e/tests/medications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Create, revise and discontinue a drug order.', async ({ page }) => {

// replay
await bahmni.goToHomePage();
await bahmni.goToMedications();
await bahmni.navigateToMedications();
await bahmni.createMedication();

// verify creation
Expand Down
24 changes: 22 additions & 2 deletions e2e/utils/functions/bahmni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export var patientName = {
updatedGivenName: '',
}

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) {}

Expand Down Expand Up @@ -48,10 +56,13 @@ export class Bahmni {
await this.page.locator('#name').fill(`${patientName.familyName}`);
await this.page.locator('form[name="searchByNameForm"]').getByRole('button', { name: 'Search' }).click();
await this.page.locator('#view-content td:nth-child(1) a').click();
await expect(this.page.locator('#givenName')).toBeVisible();
await this.page.locator('#givenName').clear();
await delay(1000);
await this.page.locator('#givenName').fill(`${patientName.updatedGivenName}`);
await this.page.getByRole('button', { name: 'Save' }).click();
patientName.givenName = `${patientName.updatedGivenName}`;
await delay(3000);
};

async voidPatient() {
Expand Down Expand Up @@ -92,11 +103,19 @@ export class Bahmni {
}

async goToHomePage() {
await this.page.goto(`${BAHMNI_URL}/bahmni/home/`);
await this.page.goto(`${BAHMNI_URL}/bahmni/home`);
await expect(this.page).toHaveURL(/.*home/);
}

async goToMedications() {
async navigateToDiagnosis() {
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.locator('#opd-tabs').getByText('Diagnosis').click();
}

async navigateToMedications() {
await this.page.getByRole('link', { name: 'Clinical' }).click();
await this.searchPatient();
await this.page.locator('#view-content :nth-child(1).btn--success').click();
Expand Down Expand Up @@ -146,5 +165,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(5000);
}
}
3 changes: 0 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const config: PlaywrightTestConfig = {
name: 'chromium',
use: {
...devices['Desktop Chromium'],
launchOptions: {
slowMo: 500
}
},
},
],
Expand Down

0 comments on commit 0703d95

Please sign in to comment.