From 0e9bcc3812e78a950532af914552fba4c46682f1 Mon Sep 17 00:00:00 2001 From: vijay Date: Sat, 15 Jun 2024 16:46:24 +0530 Subject: [PATCH] separated edit action --- e2e/commands/patient-operations.ts | 71 +++++++++++++++++++++++++--- e2e/commands/visit-operations.ts | 4 +- e2e/fixtures/api.ts | 2 +- e2e/specs/edit-immunizations.spec.ts | 55 +++++++++++++++++++++ e2e/specs/immunizations.spec.ts | 35 -------------- 5 files changed, 122 insertions(+), 45 deletions(-) create mode 100644 e2e/specs/edit-immunizations.spec.ts diff --git a/e2e/commands/patient-operations.ts b/e2e/commands/patient-operations.ts index 029d87f518..d42a5b0c5a 100644 --- a/e2e/commands/patient-operations.ts +++ b/e2e/commands/patient-operations.ts @@ -47,14 +47,16 @@ export interface Identifier { } export const generateRandomPatient = async (api: APIRequestContext): Promise => { - const identifierRes = await api.post('idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier', { - data: {}, - }); + const identifierRes = await api.post( + 'rest/v1/idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier', + { + data: {}, + }, + ); await expect(identifierRes.ok()).toBeTruthy(); const { identifier } = await identifierRes.json(); - const patientRes = await api.post('patient', { - // TODO: This is not configurable right now. It probably should be. + const patientRes = await api.post('rest/v1/patient', { data: { identifiers: [ { @@ -96,10 +98,65 @@ export const generateRandomPatient = async (api: APIRequestContext): Promise => { - const patientRes = await api.get(`patient/${uuid}?v=full`); + const patientRes = await api.get(`rest/v1/patient/${uuid}?v=full`); return await patientRes.json(); }; export const deletePatient = async (api: APIRequestContext, uuid: string) => { - await api.delete(`patient/${uuid}`, { data: {} }); + await api.delete(`rest/v1/patient/${uuid}`, { data: {} }); +}; + +export const createImmunizations = async (api: APIRequestContext, uuid: string) => { + const immunizationData = { + resourceType: 'Immunization', + status: 'completed', + vaccineCode: { + coding: [ + { + code: '783AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + display: 'Polio vaccination, oral', + }, + ], + }, + patient: { + type: 'Patient', + reference: `Patient/${uuid}`, + }, + encounter: { + type: 'Encounter', + reference: 'Encounter/fca94b00-8b1f-4468-b006-68e77f438978', + }, + occurrenceDateTime: '2024-06-10T13:50:00.000Z', + expirationDate: '2052-06-29T18:30:00.000Z', + location: { + type: 'Location', + reference: 'Location/44c3efb0-2583-4c80-a79e-1f756a03c0a1', + }, + performer: [ + { + actor: { + type: 'Practitioner', + reference: 'Practitioner/f39e57d8-1185-4199-8567-6f1eeb160f05', + }, + }, + ], + manufacturer: { + display: 'Sanofi Pasteur SA', + }, + lotNumber: 'POLIO-001', + protocolApplied: [ + { + doseNumberPositiveInt: 1, + series: null, + }, + ], + }; + + const immunizationRes = await api.post('fhir2/R4/Immunization?_summary=data', { + data: immunizationData, + }); + console.log('Immunization response:', immunizationRes); + await expect(immunizationRes.ok()).toBeTruthy(); + const immunization = await immunizationRes.json(); + return immunization; }; diff --git a/e2e/commands/visit-operations.ts b/e2e/commands/visit-operations.ts index 752a07137f..f9f13814f3 100644 --- a/e2e/commands/visit-operations.ts +++ b/e2e/commands/visit-operations.ts @@ -3,7 +3,7 @@ import { type Visit } from '@openmrs/esm-framework'; import dayjs from 'dayjs'; export const startVisit = async (api: APIRequestContext, patientId: string): Promise => { - const visitRes = await api.post('visit', { + const visitRes = await api.post('rest/v1/visit', { data: { startDatetime: dayjs().subtract(1, 'D').format('YYYY-MM-DDTHH:mm:ss.SSSZZ'), patient: patientId, @@ -18,7 +18,7 @@ export const startVisit = async (api: APIRequestContext, patientId: string): Pro }; export const endVisit = async (api: APIRequestContext, uuid: string) => { - const visitRes = await api.post(`visit/${uuid}`, { + const visitRes = await api.post(`rest/v1/visit/${uuid}`, { data: { location: process.env.E2E_LOGIN_DEFAULT_LOCATION_UUID, startDatetime: dayjs().subtract(1, 'D').format('YYYY-MM-DDTHH:mm:ss.SSSZZ'), diff --git a/e2e/fixtures/api.ts b/e2e/fixtures/api.ts index 79347e41ab..f83ffa1df0 100644 --- a/e2e/fixtures/api.ts +++ b/e2e/fixtures/api.ts @@ -15,7 +15,7 @@ import { type APIRequestContext, type PlaywrightWorkerArgs, type WorkerFixture } */ export const api: WorkerFixture = async ({ playwright }, use) => { const ctx = await playwright.request.newContext({ - baseURL: `${process.env.E2E_BASE_URL}/ws/rest/v1/`, + baseURL: `${process.env.E2E_BASE_URL}/ws/`, httpCredentials: { username: process.env.E2E_USER_ADMIN_USERNAME, password: process.env.E2E_USER_ADMIN_PASSWORD, diff --git a/e2e/specs/edit-immunizations.spec.ts b/e2e/specs/edit-immunizations.spec.ts new file mode 100644 index 0000000000..ca2a357439 --- /dev/null +++ b/e2e/specs/edit-immunizations.spec.ts @@ -0,0 +1,55 @@ +import { expect } from '@playwright/test'; +import { type Visit } from '@openmrs/esm-framework'; +import { generateRandomPatient, type Patient, startVisit, deletePatient, createImmunizations } from '../commands'; +import { test } from '../core'; +import { ImmunizationsPage } from '../pages'; + +let patient: Patient; +let visit: Visit; + +test.beforeEach(async ({ api }) => { + patient = await generateRandomPatient(api); + visit = await startVisit(api, patient.uuid); + + await createImmunizations(api, patient.uuid); +}); + +test('Edit an immunization', async ({ page }) => { + const immunizationsPage = new ImmunizationsPage(page); + + await test.step('When I go to the Immunizations page', async () => { + await immunizationsPage.goTo(patient.uuid); + }); + + await test.step('And I edit the Immunization', async () => { + await page.getByRole('button', { name: 'Expand current row' }).click(); + await page.getByRole('button', { name: 'Edit' }).click(); + }); + + await test.step('Then I should see the Immunization form launch in the workspace', async () => { + await expect(page.getByText(/immunization form/i)).toBeVisible(); + }); + + await test.step('When I set `21/03/2024` as the vaccination date', async () => { + await page.getByLabel(/vaccination date/i).clear(); + await page.getByLabel(/vaccination date/i).fill('21/03/2024'); + await page.getByLabel(/vaccination date/i).press('Tab'); + }); + + await test.step('And I set `Polio vaccination, oral` as the immunization', async () => { + await page.getByRole('combobox', { name: /immunization/i }).click(); + await page.getByText(/polio vaccination, oral/i).click(); + }); + + await test.step('And I click on the `Save` button', async () => { + await page.getByRole('button', { name: /save/i }).click(); + }); + + await test.step('Then I should see a success toast notification', async () => { + await expect(page.getByText(/Vaccination saved successfully/i)).toBeVisible(); + }); +}); + +test.afterEach(async ({ api }) => { + await deletePatient(api, patient.uuid); +}); diff --git a/e2e/specs/immunizations.spec.ts b/e2e/specs/immunizations.spec.ts index 348e388a75..b8de61d676 100644 --- a/e2e/specs/immunizations.spec.ts +++ b/e2e/specs/immunizations.spec.ts @@ -57,41 +57,6 @@ test('Add an immunization', async ({ page }) => { }); }); -test('Edit an immunization', async ({ page }) => { - const immunizationsPage = new ImmunizationsPage(page); - - await test.step('When I go to the Immunizations page', async () => { - await immunizationsPage.goTo(patient.uuid); - }); - - await test.step('And I edit the Immunization', async () => { - await page.getByRole('button', { name: 'Expand current row' }).click(); - await page.getByRole('button', { name: 'Edit' }).click(); - }); - await test.step('Then I should see the Immunization form launch in the workspace', async () => { - await expect(page.getByText(/immunization form/i)).toBeVisible(); - }); - - await test.step('When I set `21/03/2024` as the vaccination date', async () => { - await page.getByLabel(/vaccination date/i).clear(); - await page.getByLabel(/vaccination date/i).fill('21/03/2024'); - await page.getByLabel(/vaccination date/i).press('Tab'); - }); - - await test.step('And I set `Polio vaccination, oral` as the immunization', async () => { - await page.getByRole('combobox', { name: /immunization/i }).click(); - await page.getByText(/polio vaccination, oral/i).click(); - }); - - await test.step('And I click on the `Save` button', async () => { - await page.getByRole('button', { name: /save/i }).click(); - }); - - await test.step('Then I should see a success toast notification', async () => { - await expect(page.getByText(/Vaccination saved successfully/i)).toBeVisible(); - }); -}); - test.afterEach(async ({ api }) => { await deletePatient(api, patient.uuid); });