From 24128587169a15d5fa12ef63db3fa8c38b2553d5 Mon Sep 17 00:00:00 2001 From: kdaud Date: Wed, 21 Aug 2024 14:36:58 +0300 Subject: [PATCH] E2E test for diagnosis workflows --- e2e/tests/diagnosis.spec.ts | 70 +++++++++++++++++++++++++++++++++++ e2e/utils/functions/bahmni.ts | 8 ++++ playwright.config.ts | 6 ++- 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 e2e/tests/diagnosis.spec.ts diff --git a/e2e/tests/diagnosis.spec.ts b/e2e/tests/diagnosis.spec.ts new file mode 100644 index 0000000..cfd27bb --- /dev/null +++ b/e2e/tests/diagnosis.spec.ts @@ -0,0 +1,70 @@ +import { test, expect } from '@playwright/test'; +import { Odoo } from '../utils/functions/odoo'; +import { Bahmni } from '../utils/functions/bahmni'; + +let bahmni: Bahmni; +let odoo: Odoo; + +test.beforeEach(async ({ page }) => { + bahmni = new Bahmni(page); + odoo = new Odoo(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, revise and discontinue diagnosis.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + + // replay + await bahmni.goToDiagnosis(); + 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 page.locator('#name-1').fill('Diphtheria (A36.9)'); + await page.getByText('Diphtheria (A36.9)').click(); + await page.locator('#order-1').getByRole('button', { name: /secondary/i }).click(); + await page.locator('#certainty-1').getByRole('button', { name: /presumed/i }).click(); + await bahmni.saveOrder(); + + // verify creation + await page.locator('#dashboard-link span.patient-name').click(); + const primaryDiagnosisSelector = await page.locator('#diagnosisName').nth(0); + const secondaryDiagnosisSelector = await page.locator('#diagnosisName').nth(1); + const primaryDiagnosisCertaintySelector = await page.locator('#certainty').nth(0); + const seconadryDiagnosisCertaintySelector = await page.locator('#certainty').nth(1); + + await expect(primaryDiagnosisSelector).toContainText('Candidiasis'); + await expect(secondaryDiagnosisSelector).toContainText('Diphtheria'); + await expect(primaryDiagnosisCertaintySelector).toContainText(/confirmed/i); + await expect(seconadryDiagnosisCertaintySelector).toContainText(/presumed/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(); + await page.getByRole('button', { name: /confirmed/i }).click(); + await page.getByRole('button', { name: /presumed/i }).nth(1).click(); + await bahmni.saveOrder(); + await page.locator('i.fa.fa-edit').nth(1).click(); + await page.getByRole('button', { name: /presumed/i }).click(); + await page.getByRole('button', { name: /confirmed/i }).nth(1).click(); + await bahmni.saveOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(primaryDiagnosisCertaintySelector).toContainText(/presumed/i); + await expect(seconadryDiagnosisCertaintySelector).toContainText(/confirmed/i); + + // verify revision +}); + +test.afterEach(async ({ page }) => { + await bahmni.voidPatient(); + await page.close(); +}); diff --git a/e2e/utils/functions/bahmni.ts b/e2e/utils/functions/bahmni.ts index ede1c3f..5a4d1b6 100644 --- a/e2e/utils/functions/bahmni.ts +++ b/e2e/utils/functions/bahmni.ts @@ -60,6 +60,14 @@ export class Bahmni { await expect(this.page.getByText('Lab Samples')).toBeVisible(); } + async goToDiagnosis() { + 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 goToMedications() { await this.page.locator('i.fa.fa-home').click(); await this.page.getByRole('link', { name: 'Clinical' }).click(); diff --git a/playwright.config.ts b/playwright.config.ts index e85b4da..3a7026c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -24,8 +24,10 @@ const config: PlaywrightTestConfig = { use: { ...devices['Desktop Chromium'], launchOptions: { - slowMo: 500 - } + slowMo: 500, + }, + screenshot: 'only-on-failure', + video: 'retain-on-failure' }, },