Skip to content

Commit

Permalink
C2C-355: E2E tests for the observation forms
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud committed Sep 16, 2024
1 parent 0703d95 commit 0166583
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 114 deletions.
129 changes: 48 additions & 81 deletions e2e/tests/bahmni-odoo-flows.spec.ts

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions e2e/tests/diagnosis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ test('Create and revise a diagnosis.', async ({ page }) => {
await bahmni.registerPatient();

// replay
await bahmni.navigateToPatientDashboard();
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();
await bahmni.save();

// verify creation
await page.locator('#dashboard-link span.patient-name').click();
Expand All @@ -41,7 +42,7 @@ test('Create and revise a diagnosis.', async ({ page }) => {
await diagnosisOrderButton.waitFor({ state: 'visible' });
await diagnosisOrderButton.focus();
await diagnosisOrderButton.click();
await bahmni.saveOrder();
await bahmni.save();
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);
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests/lab-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ test('Create, revise and discontinue lab tests.', async ({ page }) => {
await bahmni.registerPatient();

// replay
await bahmni.goToHomePage();
await bahmni.goToLabSamples();
await bahmni.navigateToPatientDashboard();
await bahmni.navigateToLabSamples();
await page.getByText('Blood', { exact: true }).click();
await page.getByText('Malaria').click();
await page.getByText('Urine').click();
Expand All @@ -31,7 +31,7 @@ test('Create, revise and discontinue lab tests.', async ({ page }) => {
await page.getByText('Bacteries').click();
await page.getByText('Sputum').click();
await page.getByText('Serial sputum bacilloscopy').click();
await bahmni.saveOrder();
await bahmni.save();

// verify creation
await page.locator('#dashboard-link span.patient-name').click();
Expand All @@ -52,7 +52,7 @@ test('Create, revise and discontinue lab tests.', async ({ page }) => {
await page.getByText('Urine Colour').click();
await page.getByText('Stool', { exact: true }).click();
await page.getByText('Stool Parasites').click();
await bahmni.saveOrder();
await bahmni.save();

// verify revision
await page.locator('#dashboard-link span.patient-name').click();
Expand All @@ -71,7 +71,7 @@ test('Create, revise and discontinue lab tests.', async ({ page }) => {
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 bahmni.save();
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();
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/medications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('Create, revise and discontinue a drug order.', async ({ page }) => {
await bahmni.registerPatient();

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

Expand All @@ -45,7 +45,7 @@ test('Create, revise and discontinue a drug order.', async ({ page }) => {
await page.locator('#uniform-dose-unit').selectOption('string:Comprime(s)');
await page.locator('#route').selectOption('string:Inhalation');
await page.getByRole('button', { name: 'Add' }).click();
await bahmni.saveOrder();
await bahmni.save();
await expect(medicationDetailsSelector).not.toContainText('2 Application(s)');
await expect(medicationDetailsSelector).toContainText('4 Comprime(s)');
await expect(medicationDetailsSelector).not.toContainText('Q3H');
Expand All @@ -57,7 +57,7 @@ test('Create, revise and discontinue a drug order.', async ({ page }) => {
await expect(drugNameSelector).toContainText('Aspirine Co 81mg (Comprime)');
await page.getByRole('button', { name: 'Stop' }).first().click();
await page.getByPlaceholder('Notes').fill('Patient allergic to medicine');
await bahmni.saveOrder();
await bahmni.save();
await page.locator('#dashboard-link span.patient-name').click();
const medicationStatus = await page.locator('#dashboard-treatments span.discontinued-text').first();
await expect(medicationStatus).toContainText('Stopped');
Expand Down
125 changes: 125 additions & 0 deletions e2e/tests/observation-forms.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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('Anthropometry form should save observations.', async ({ page }) => {
// setup
await bahmni.registerPatient();

// replay
await bahmni.navigateToPatientDashboard();
await bahmni.navigateToForms();
await page.getByRole('button', { name: 'Anthropométrie' }).click();
await expect(page.getByText('Anthropométrie added successfully')).toBeVisible();
await bahmni.fillAnthropometryForm();

// verify
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('a.visit')).toBeVisible();
await page.locator('a.visit').click();
await expect(page.locator('#observationSection h2')).toHaveText('Observations');
await expect(page.locator('#observationSection').getByText('BMI Data')).toBeVisible();
await expect(page.locator('#observationSection').getByText('22.49')).toBeVisible();
await expect(page.locator('#observationSection').getByText('BMI Status Data')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Normal')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Height')).toBeVisible();
await expect(page.locator('#observationSection').getByText('170')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Weight')).toBeVisible();
await expect(page.locator('#observationSection').getByText('65')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Head Circumference')).toBeVisible();
await expect(page.locator('#observationSection').getByText('23')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Abdominal Diameter')).toBeVisible();
await expect(page.locator('#observationSection').getByText('25.5')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Mid-Upper Arm Circumference')).toBeVisible();
await expect(page.locator('#observationSection').getByText('24', {exact: true})).toBeVisible();
});

test('Gynecological ultrasound form should save observations.', async ({ page }) => {
// setup
await bahmni.registerPatient();

// replay
await bahmni.navigateToPatientDashboard();
await bahmni.navigateToForms();
await page.getByRole('button', { name: 'Echographie gynécologique' }).click();
await expect(page.getByText('Echographie gynécologique added successfully')).toBeVisible();
await bahmni.fillGynecologicalUltrasoundForm();

// verify
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('a.visit')).toBeVisible();
await page.locator('a.visit').click();
await expect(page.getByText('Echographie gynécologique')).toBeVisible();
await expect(page.locator('div:nth-child(2) span.value-text-only').getByText('Normal left ovary. The right ovary contains a complex mass. No free fluid in the pelvis.')).toBeVisible();
});

test('Obstetric ultrasound 3 form should save observations.', async ({ page }) => {
// setup
await bahmni.registerPatient();

// replay
await bahmni.navigateToPatientDashboard();
await bahmni.navigateToForms();
await page.getByRole('button', { name: 'Echographie obstétricale 3' }).click();
await expect(page.getByText('Echographie obstétricale 3 added successfully')).toBeVisible();
await bahmni.fillObstetricUltrasound3Form();

// verify
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('a.visit')).toBeVisible();
await page.locator('a.visit').click();
await expect(page.getByText('Echographie obstétricale 3')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Number of Fetuses')).toBeVisible();
await expect(page.locator('#observationSection').getByText('2', {exact: true}).nth(0)).toBeVisible();
await expect(page.locator('#observationSection').getByText('Number of Placenta')).toBeVisible();
await expect(page.locator('#observationSection').getByText('2', {exact: true}).nth(1)).toBeVisible();
await expect(page.locator('#observationSection').getByText('Localisation de Placenta')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Posterior')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Presentation')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Transverse')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Other observations')).toBeVisible();
await expect(page.locator('#observationSection').getByText('The two fetuses are in a good growing state.')).toBeVisible();
});

test('Physical examination form should save observations.', async ({ page }) => {
// setup
await bahmni.registerPatient();

// replay
await bahmni.navigateToPatientDashboard();
await bahmni.navigateToForms();
await page.getByRole('button', { name: 'Examen physique' }).click();
await expect(page.getByText('Examen physique added successfully')).toBeVisible();
await bahmni.fillPhysicalExaminationForm();

// verify
await page.locator('#dashboard-link span.patient-name').click();
await expect(page.locator('a.visit')).toBeVisible();
await page.locator('a.visit').click();
await expect(page.getByText('Examen physique')).toBeVisible();
await expect(page.locator('#observationSection').getByText('General Examination')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Normal').nth(0)).toBeVisible();
await expect(page.locator('#observationSection').getByText('Cardiovascular Examination', {exact: true})).toBeVisible();
await expect(page.locator('#observationSection').getByText('Abnormal').nth(0)).toBeVisible();
await expect(page.locator('#observationSection').getByText('Cardiovascular Examination Details')).toBeVisible();
await expect(page.locator('#observationSection').getByText('The blood vessels are very narrow.')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Respiratory Examination')).toBeVisible();
await expect(page.locator('#observationSection').getByText('Normal').nth(1)).toBeVisible()
});

test.afterEach(async ({ page }) => {
await bahmni.voidPatient();
await page.close();
});
74 changes: 56 additions & 18 deletions e2e/utils/functions/bahmni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Bahmni {
await this.page.locator('#password').fill(`${process.env.BAHMNI_PASSWORD}`);
await this.page.locator('#location').selectOption('object:7');
await this.page.getByRole('button', { name: 'Login' }).click();
await expect(this.page).toHaveURL(/.*home/);
}

async registerPatient() {
Expand Down Expand Up @@ -62,11 +63,12 @@ export class Bahmni {
await this.page.locator('#givenName').fill(`${patientName.updatedGivenName}`);
await this.page.getByRole('button', { name: 'Save' }).click();
patientName.givenName = `${patientName.updatedGivenName}`;
await delay(3000);
await delay(6000);
};

async voidPatient() {
await this.page.goto(`${BAHMNI_URL}/openmrs/admin/patients/index.htm`);
await expect(this.page.getByPlaceholder(' ')).toBeVisible();
await this.page.getByPlaceholder(' ').type(`${patientName.familyName}`);
await this.page.locator('#openmrsSearchTable tbody tr.odd td:nth-child(1)').click();
await this.page.locator('input[name="voidReason"]').fill('Void patient created by smoke test');
Expand All @@ -75,9 +77,7 @@ export class Bahmni {
await expect(message?.includes('This patient has been deleted')).toBeTruthy();
}

async goToLabSamples() {
await this.page.getByRole('link', { name: 'Clinical' }).click();
await this.searchPatient();
async navigateToLabSamples() {
await this.page.locator('#view-content :nth-child(1).btn--success').click();
await this.page.locator('#opd-tabs').getByText('Orders').click();
await expect(this.page.getByText('Lab Samples')).toBeVisible();
Expand All @@ -86,38 +86,76 @@ export class Bahmni {
async createLabOrder() {
await this.page.getByText('Blood', { exact: true }).click();
await this.page.getByText('Malaria').click();
await this.saveOrder();
await this.save();
}

async reviseLabOrder() {
await this.page.getByText('Blood', { exact: true }).click();
await this.page.locator('#selected-orders li').filter({ hasText: 'Malaria' }).locator('i').nth(1).click();
await this.page.getByText('Hematocrit').click();
await this.saveOrder();
await this.save();
}

async discontinueLabOrder() {
await this.page.getByText('Blood', { exact: true }).click();
await this.page.locator('#selected-orders li').filter({ hasText: 'Malaria' }).locator('i').nth(1).click();
await this.saveOrder();
await this.save();
}

async goToHomePage() {
async navigateToPatientDashboard() {
await this.page.goto(`${BAHMNI_URL}/bahmni/home`);
await expect(this.page).toHaveURL(/.*home/);
await this.page.getByRole('link', { name: 'Clinical' }).click();
await this.searchPatient();
}

async navigateToForms() {
await this.page.locator('#view-content :nth-child(1).btn--success').click();
await expect(this.page.getByRole('button', { name: 'Add New Obs Form' })).toBeVisible();
await this.page.getByRole('button', { name: 'Add New Obs Form' }).click();
}

async fillAnthropometryForm() {
await this.page.locator('input[type=number]').nth(0).fill('170');
await this.page.locator('input[type=number]').nth(1).fill('65');
await this.page.locator('input[type=number]').nth(2).fill('23');
await this.page.locator('input[type=number]').nth(3).fill('25.5');
await this.page.locator('input[type=number]').nth(4).fill('24');
await this.save();
}

async fillGynecologicalUltrasoundForm() {
await expect(this.page.locator('div.obs-control-field textarea')).toBeVisible();
await this.page.locator('div.obs-control-field textarea').fill('Normal left ovary. The right ovary contains a complex mass. No free fluid in the pelvis.');
await this.save();
}

async fillObstetricUltrasound3Form() {
await expect(this.page.locator('div.obs-control-field textarea')).toBeVisible();
await this.page.locator('.fl input').nth(0).fill('2');
await this.page.locator('.fl input').nth(1).fill('2');
await this.page.getByRole('button', { name: 'Posterior' }).click();
await this.page.getByRole('button', { name: 'Transverse' }).click();
await this.page.getByRole('textbox').fill('The two fetuses are in a good growing state.');
await this.save();
}

async fillPhysicalExaminationForm() {
await expect(this.page.locator('span.section-label')).toHaveText('Examen physique');
await this.page.locator(':nth-child(3)>.form-builder-column-wrapper button').first().click();
await this.page.locator(':nth-child(7)>.form-builder-column-wrapper :nth-child(2)').nth(1).click();
await expect(this.page.getByText('Cardiovascular Examination Details')).toBeVisible();
await expect(this.page.locator('div textarea')).toBeVisible();
await this.page.locator('div textarea').fill('The blood vessels are very narrow.');
await this.page.locator(':nth-child(9)>.form-builder-column-wrapper button').first().click();
await this.save();
}

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();
await this.page.locator('#opd-tabs').getByText('Medications').click();
await expect(this.page.getByText('Order Drug')).toBeVisible();
Expand All @@ -139,7 +177,7 @@ export class Bahmni {
await this.page.locator('#additional-instructions').fill('Take after a meal');
await expect(this.page.locator('#quantity')).toHaveValue('560');
await this.page.getByRole('button', { name: 'Add' }).click();
await this.saveOrder();
await this.save();
}

async editMedicationDetails() {
Expand All @@ -150,19 +188,19 @@ export class Bahmni {
await this.page.locator('#uniform-dose-unit').selectOption('string:Comprime(s)');
await this.page.locator('#route').selectOption('string:Inhalation');
await this.page.getByRole('button', { name: 'Add' }).click();
await this.saveOrder();
await this.save();
}

async discontinueMedication() {
await this.page.getByRole('button', { name: 'Stop' }).first().click();
await this.page.getByPlaceholder('Notes').fill('Patient allergic to medicine');
await this.saveOrder();
await this.save();
await this.page.locator('#dashboard-link span.patient-name').click();
const medicationStatus = await this.page.locator('#dashboard-treatments span.discontinued-text').first();
await expect(medicationStatus).toContainText('Stopped');
}

async saveOrder() {
async save() {
await this.page.getByRole('button', { name: 'Save' }).click();
await expect(this.page.getByText('Saved', {exact: true})).toBeVisible();
await delay(5000);
Expand Down
9 changes: 6 additions & 3 deletions e2e/utils/functions/odoo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Page } from '@playwright/test';
import { patientName } from './bahmni';
import { expect, Page } from '@playwright/test';
import { delay, patientName } from './bahmni';
import { ODOO_URL } from '../configs/globalSetup';

export class Odoo {
Expand All @@ -10,12 +10,15 @@ export class Odoo {
await this.page.getByPlaceholder('Email').fill(`${process.env.ODOO_USERNAME}`);
await this.page.getByPlaceholder('Password').fill(`${process.env.ODOO_PASSWORD}`);
await this.page.locator('button[type="submit"]').click();
await expect(this.page).toHaveURL(/.*web/);
}

async searchCustomer() {
await this.page.locator("//a[contains(@class, 'full')]").click();
await delay(2000);
await this.page.locator('ul.o_menu_apps a:nth-child(2)').click();
await this.page.locator('input.o_searchview_input').fill(`${patientName.givenName + ' ' + patientName.familyName}`);
await expect(this.page.locator('.breadcrumb-item')).toHaveText('Devis');
await this.page.locator('input.o_searchview_input').type(`${patientName.givenName + ' ' + patientName.familyName}`);
await this.page.locator('input.o_searchview_input').press('Enter');
}
}
Loading

0 comments on commit 0166583

Please sign in to comment.