Skip to content

Commit

Permalink
separated edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijaykv5 committed Jun 24, 2024
1 parent a4b4cb5 commit 0e9bcc3
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 45 deletions.
71 changes: 64 additions & 7 deletions e2e/commands/patient-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ export interface Identifier {
}

export const generateRandomPatient = async (api: APIRequestContext): Promise<Patient> => {
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: [
{
Expand Down Expand Up @@ -96,10 +98,65 @@ export const generateRandomPatient = async (api: APIRequestContext): Promise<Pat
};

export const getPatient = async (api: APIRequestContext, uuid: string): Promise<Patient> => {
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;
};
4 changes: 2 additions & 2 deletions e2e/commands/visit-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Visit } from '@openmrs/esm-framework';
import dayjs from 'dayjs';

export const startVisit = async (api: APIRequestContext, patientId: string): Promise<Visit> => {
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,
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { type APIRequestContext, type PlaywrightWorkerArgs, type WorkerFixture }
*/
export const api: WorkerFixture<APIRequestContext, PlaywrightWorkerArgs> = 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,
Expand Down
55 changes: 55 additions & 0 deletions e2e/specs/edit-immunizations.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
35 changes: 0 additions & 35 deletions e2e/specs/immunizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 0e9bcc3

Please sign in to comment.