From 282a4896edaa716b0068533f995e2d8b2e4aab09 Mon Sep 17 00:00:00 2001 From: chimanwadike Date: Mon, 19 Aug 2024 17:08:02 +0100 Subject: [PATCH 1/2] (chore) O3-3574: refactored test to have separate test for adding appointment --- e2e/specs/appointments.spec.ts | 62 +--------------------------------- 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/e2e/specs/appointments.spec.ts b/e2e/specs/appointments.spec.ts index 982dd9caa..f3353449a 100644 --- a/e2e/specs/appointments.spec.ts +++ b/e2e/specs/appointments.spec.ts @@ -12,7 +12,7 @@ test.beforeEach(async ({ api }) => { visit = await startVisit(api, patient.uuid); }); -test('Add, edit and cancel an appointment', async ({ page, api }) => { +test('Add an appointment', async ({ page, api }) => { const appointmentsPage = new AppointmentsPage(page); await test.step('When I go to the Appointments page in the patient chart', async () => { @@ -59,66 +59,6 @@ test('Add, edit and cancel an appointment', async ({ page, api }) => { await test.step('Then I should see a success message', async () => { await expect(page.getByText(/appointment scheduled/i)).toBeVisible(); }); - - await test.step('When I click the overflow menu on the table row with the newly created appointment', async () => { - await page.getByRole('button', { name: 'Options' }).click(); - }); - - await test.step('And I choose the "Edit" option from the popup menu', async () => { - await page.getByRole('menuitem', { name: 'Edit' }).click(); - }); - - await test.step('When I change to “Inpatient ward” location', async () => { - await page.selectOption('select#service', { label: 'General Medicine service' }); - }); - - await test.step('And I change to “General Medicine” Service', async () => { - await page.getByLabel('Select a service').selectOption('General Medicine service'); - }); - - await test.step('And I change the date to Today', async () => { - const today = new Date(); - today.setDate(today.getDate()); - await page.getByLabel(/^Date$/i).fill(today.toLocaleDateString('en-GB')); - }); - - await test.step('And I set the “Duration” of the appointment”', async () => { - await page.getByLabel('Duration (minutes)').fill('80'); - }); - - await test.step('And I change the note', async () => { - await page - .getByPlaceholder('Write any additional points here') - .fill('A sample note for testing out the edit flow for scheduled appointments'); - }); - - await test.step('And I click Save button', async () => { - await page.getByRole('button', { name: /save and close/i }).click(); - }); - - await test.step('Then I should see a success message', async () => { - await expect(page.getByText(/appointment edited/i)).toBeVisible(); - }); - - await test.step('When I click the "Today" tab', async () => { - await page.getByRole('tab', { name: /today/i }).click(); - }); - - await test.step('Then I click the options kebab menu in the appointment', async () => { - await page.getByRole('button', { name: 'Options' }).click(); - }); - - await test.step('And I choose the "Cancel" option ', async () => { - await page.getByRole('menuitem', { name: 'Cancel' }).click(); - }); - - await test.step('When I click the "Cancel appointment" button to confirm', async () => { - await page.getByRole('button', { name: 'danger Cancel appointment' }).click(); - }); - - await test.step('Then I should see a success message', async () => { - await expect(page.getByText(/appointment cancelled successfully/i)).toBeVisible(); - }); }); test.afterEach(async ({ api }) => { From ea557793b00a80c0412217cb1c57f19a68c466fc Mon Sep 17 00:00:00 2001 From: chimanwadike Date: Mon, 19 Aug 2024 18:42:49 +0100 Subject: [PATCH 2/2] (chore) O3-3574: refactored test to have separate test for editing and canceling appointment --- e2e/specs/appointments.spec.ts | 149 +++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 36 deletions(-) diff --git a/e2e/specs/appointments.spec.ts b/e2e/specs/appointments.spec.ts index f3353449a..845846741 100644 --- a/e2e/specs/appointments.spec.ts +++ b/e2e/specs/appointments.spec.ts @@ -7,61 +7,138 @@ import { type Visit } from '@openmrs/esm-framework'; let patient: Patient; let visit: Visit; -test.beforeEach(async ({ api }) => { +test.beforeAll(async ({ api }) => { patient = await generateRandomPatient(api); visit = await startVisit(api, patient.uuid); }); -test('Add an appointment', async ({ page, api }) => { - const appointmentsPage = new AppointmentsPage(page); +test.describe.serial('Running appointment tests sequentially', () => { + test('Add an appointment', async ({ page }) => { + const appointmentsPage = new AppointmentsPage(page); + await test.step('When I go to the Appointments page in the patient chart', async () => { + await appointmentsPage.goto(patient.uuid); + }); - await test.step('When I go to the Appointments page in the patient chart', async () => { - await appointmentsPage.goto(patient.uuid); - }); + await test.step('And I click on the “Add” button', async () => { + await page.getByRole('button', { name: 'Add', exact: true }).click(); + }); - await test.step('And I click on the “Add” button', async () => { - await page.getByRole('button', { name: 'Add', exact: true }).click(); - }); + // FIXME: Login locations are failing to populate in this dropdown in the test environment + // await test.step('And I select Mobile Clinic location', async () => { + // await page.getByLabel('Select location').selectOption('Mobile Clinic'); + // }); - // FIXME: Login locations are failing to populate in this dropdown in the test environment - // await test.step('And I select Mobile Clinic location', async () => { - // await page.getByLabel('Select location').selectOption('Mobile Clinic'); - // }); + await test.step('And I select “Outpatient Department” service', async () => { + await page.selectOption('select#service', { label: 'Outpatient Department' }); + }); - await test.step('And I select “Outpatient Department” service', async () => { - await page.selectOption('select#service', { label: 'Outpatient Department' }); - }); + await test.step('And I make appointment as “Scheduled”', async () => { + await page.getByLabel('Select an appointment type').selectOption('Scheduled'); + }); - await test.step('And I make appointment as “Scheduled”', async () => { - await page.getByLabel('Select an appointment type').selectOption('Scheduled'); - }); + await test.step('And I set date for tomorrow', async () => { + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + await page.getByLabel(/^Date$/i).fill(tomorrow.toLocaleDateString('en-GB')); + }); - await test.step('And I set date for tomorrow', async () => { - const tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 1); - await page.getByLabel(/^Date$/i).fill(tomorrow.toLocaleDateString('en-GB')); - }); + await test.step('And I set the “Duration” to 60', async () => { + await page.getByLabel('Duration (minutes)').fill('60'); + }); - await test.step('And I set the “Duration” to 60', async () => { - await page.getByLabel('Duration (minutes)').fill('60'); - }); + await test.step('And I add a note', async () => { + await page + .getByPlaceholder(/write any additional points here/i) + .fill('A sample note for testing out the appointment scheduling flow'); + }); - await test.step('And I add a note', async () => { - await page - .getByPlaceholder(/write any additional points here/i) - .fill('A sample note for testing out the appointment scheduling flow'); + await test.step('And I click Save button', async () => { + await page.getByRole('button', { name: /save and close/i }).click(); + }); + + await test.step('Then I should see a success message', async () => { + await expect(page.getByText(/appointment scheduled/i)).toBeVisible(); + }); }); - await test.step('And I click Save button', async () => { - await page.getByRole('button', { name: /save and close/i }).click(); + test('Edit an appointment', async ({ page }) => { + const appointmentsPage = new AppointmentsPage(page); + + await test.step('When I go to the Appointments page in the patient chart', async () => { + await appointmentsPage.goto(patient.uuid); + }); + + await test.step('When I click the overflow menu on the table row with the newly created appointment', async () => { + await page.getByRole('button', { name: 'Options' }).click(); + }); + + await test.step('And I choose the "Edit" option from the popup menu', async () => { + await page.getByRole('menuitem', { name: 'Edit' }).click(); + }); + + await test.step('When I change to “Inpatient ward” location', async () => { + await page.selectOption('select#service', { label: 'General Medicine service' }); + }); + + await test.step('And I change to “General Medicine” Service', async () => { + await page.getByLabel('Select a service').selectOption('General Medicine service'); + }); + + await test.step('And I change the date to Today', async () => { + const today = new Date(); + today.setDate(today.getDate()); + await page.getByLabel(/^Date$/i).fill(today.toLocaleDateString('en-GB')); + }); + + await test.step('And I set the “Duration” of the appointment”', async () => { + await page.getByLabel('Duration (minutes)').fill('80'); + }); + + await test.step('And I change the note', async () => { + await page + .getByPlaceholder('Write any additional points here') + .fill('A sample note for testing out the edit flow for scheduled appointments'); + }); + + await test.step('And I click Save button', async () => { + await page.getByRole('button', { name: /save and close/i }).click(); + }); + + await test.step('Then I should see a success message', async () => { + await expect(page.getByText(/appointment edited/i)).toBeVisible(); + }); }); - await test.step('Then I should see a success message', async () => { - await expect(page.getByText(/appointment scheduled/i)).toBeVisible(); + test('Cancel an appointment', async ({ page }) => { + const appointmentsPage = new AppointmentsPage(page); + + await test.step('When I go to the Appointments page in the patient chart', async () => { + await appointmentsPage.goto(patient.uuid); + }); + + await test.step('When I click the "Today" tab', async () => { + await page.getByRole('tab', { name: /today/i }).click(); + }); + + await test.step('Then I click the options kebab menu in the appointment', async () => { + await page.getByRole('button', { name: 'Options' }).click(); + }); + + await test.step('And I choose the "Cancel" option ', async () => { + await page.getByRole('menuitem', { name: 'Cancel' }).click(); + }); + + await test.step('When I click the "Cancel appointment" button to confirm', async () => { + await page.getByRole('button', { name: 'danger Cancel appointment' }).click(); + }); + + await test.step('Then I should see a success message', async () => { + await expect(page.getByText(/appointment cancelled successfully/i)).toBeVisible(); + }); }); }); -test.afterEach(async ({ api }) => { +test.afterAll(async ({ api }) => { await endVisit(api, visit.uuid); await deletePatient(api, patient.uuid); });