diff --git a/e2e/tests/bahmni-odoo-flows.spec.ts b/e2e/tests/bahmni-odoo-flows.spec.ts index d7e547f..e70737b 100644 --- a/e2e/tests/bahmni-odoo-flows.spec.ts +++ b/e2e/tests/bahmni-odoo-flows.spec.ts @@ -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'); }); @@ -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}`); @@ -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 }) => { @@ -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 @@ -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'); @@ -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 @@ -121,14 +121,14 @@ 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(); @@ -136,25 +136,25 @@ test('Ordering a drug for a Bahmni patient creates the corresponding Odoo custom // 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 @@ -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 @@ -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 diff --git a/e2e/tests/diagnosis.spec.ts b/e2e/tests/diagnosis.spec.ts new file mode 100644 index 0000000..5d0f14d --- /dev/null +++ b/e2e/tests/diagnosis.spec.ts @@ -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(); +}); diff --git a/e2e/tests/medications.spec.ts b/e2e/tests/medications.spec.ts index 23bcca6..b89af2b 100644 --- a/e2e/tests/medications.spec.ts +++ b/e2e/tests/medications.spec.ts @@ -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 diff --git a/e2e/utils/functions/bahmni.ts b/e2e/utils/functions/bahmni.ts index 9b39f4e..fe757fc 100644 --- a/e2e/utils/functions/bahmni.ts +++ b/e2e/utils/functions/bahmni.ts @@ -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) {} @@ -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() { @@ -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(); @@ -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); } } diff --git a/playwright.config.ts b/playwright.config.ts index 23720b1..2a7aa43 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -23,9 +23,6 @@ const config: PlaywrightTestConfig = { name: 'chromium', use: { ...devices['Desktop Chromium'], - launchOptions: { - slowMo: 500 - } }, }, ],