Skip to content

Commit

Permalink
fix: fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Oct 22, 2024
1 parent a3631a1 commit 5d5ac23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
18 changes: 12 additions & 6 deletions e2e/specs/edit-existing-visit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@playwright/test';
import { type Visit } from '@openmrs/esm-framework';
import { type Patient, generateRandomPatient, deletePatient, startVisit } from '../commands';
import { deletePatient, generateRandomPatient, type Patient, startVisit } from '../commands';
import { test } from '../core';
import { ChartPage, VisitsPage } from '../pages';

Expand All @@ -27,18 +27,24 @@ test('Edit an existing visit', async ({ page }) => {

await test.step('Then I should see the `Edit Visit` form launch in the workspace', async () => {
await expect(chartPage.page.getByText(/visit start date and time/i)).toBeVisible();
const datePickerInput = chartPage.page.getByPlaceholder(/dd\/mm\/yyyy/i);
await expect(datePickerInput).toBeVisible();
const dateValue = await datePickerInput.inputValue();

const startDateInput = chartPage.page.locator('input#visitStartDateInput');
const startTimeInput = chartPage.page.locator('input#visitStartTime');

await expect(startDateInput).toBeVisible();
const dateValue = await startDateInput.inputValue();
expect(dateValue).not.toBe('');
expect(dateValue).toMatch(/^\d{2}\/\d{2}\/\d{4}$/);

await expect(chartPage.page.getByPlaceholder(/hh\:mm/i)).toBeVisible();
await expect(startTimeInput).toBeVisible();
const timeValue = await startTimeInput.inputValue();
expect(timeValue).toMatch(/^(1[0-2]|0?[1-9]):([0-5][0-9])$/);

await expect(chartPage.page.getByRole('combobox', { name: /select a location/i })).toBeVisible();
await expect(chartPage.page.getByRole('combobox', { name: /select a location/i })).toHaveValue('Outpatient Clinic');
await expect(chartPage.page.getByText(/visit type/i)).toBeVisible();
await expect(chartPage.page.getByLabel(/facility visit/i)).toBeChecked();
await expect(chartPage.page.getByRole('search', { name: /search for a visit type/i })).toBeVisible();
await expect(chartPage.page.getByRole('search', { name: /visit type/i })).toBeVisible();
await expect(chartPage.page.getByLabel(/facility visit/i)).toBeVisible();
await expect(chartPage.page.getByLabel(/home visit/i)).toBeVisible();
await expect(chartPage.page.getByLabel(/opd visit/i)).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
return new Date(visitStartDatetime) <= new Date();
};

const hadPreviousStopDateTime = Boolean(visitToEdit?.stopDatetime);

return z
.object({
visitStartDate: z.date().refine(
Expand All @@ -167,13 +169,17 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
.string()
.refine((value) => value.match(time12HourFormatRegex), t('invalidTimeFormat', 'Invalid time format')),
visitStartTimeFormat: z.enum(['PM', 'AM']),
visitStopDate: displayVisitStopDateTimeFields ? z.date() : z.date().optional(),
visitStopTime: displayVisitStopDateTimeFields
? z
.string()
.refine((value) => value.match(time12HourFormatRegex), t('invalidTimeFormat', 'Invalid time format'))
: z.string().optional(),
visitStopTimeFormat: displayVisitStopDateTimeFields ? z.enum(['PM', 'AM']) : z.enum(['PM', 'AM']).optional(),
visitStopDate: displayVisitStopDateTimeFields && hadPreviousStopDateTime ? z.date() : z.date().optional(),
visitStopTime:
displayVisitStopDateTimeFields && hadPreviousStopDateTime
? z
.string()
.refine((value) => value.match(time12HourFormatRegex), t('invalidTimeFormat', 'Invalid time format'))
: z.string().optional(),
visitStopTimeFormat:
displayVisitStopDateTimeFields && hadPreviousStopDateTime
? z.enum(['PM', 'AM'])
: z.enum(['PM', 'AM']).optional(),
programType: z.string().optional(),
visitType: z.string().refine((value) => !!value, t('visitTypeRequired', 'Visit type is required')),
visitLocation: z.object({
Expand All @@ -186,7 +192,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
message: t('futureStartTime', 'Visit start time cannot be in the future'),
path: ['visitStartTime'],
});
}, [t, config, displayVisitStopDateTimeFields]);
}, [config.visitAttributeTypes, visitToEdit?.stopDatetime, t, displayVisitStopDateTimeFields]);

const defaultValues = useMemo(() => {
const visitStartDate = visitToEdit?.startDatetime ? new Date(visitToEdit?.startDatetime) : new Date();
Expand Down

0 comments on commit 5d5ac23

Please sign in to comment.