diff --git a/src/components/inputs/unspecified/unspecified.test.tsx b/src/components/inputs/unspecified/unspecified.test.tsx index 73e43c6ef..d37d07fe2 100644 --- a/src/components/inputs/unspecified/unspecified.test.tsx +++ b/src/components/inputs/unspecified/unspecified.test.tsx @@ -1,6 +1,5 @@ import React from 'react'; import dayjs from 'dayjs'; -import { parseDate } from '@internationalized/date'; import { fireEvent, render, screen } from '@testing-library/react'; import { OpenmrsDatePicker } from '@openmrs/esm-framework'; import { Formik } from 'formik'; @@ -18,8 +17,8 @@ mockOpenmrsDatePicker.mockImplementation(({ id, labelText, value, onChange }) => onChange(parseDate(dayjs(evt.target.value).format('YYYY-MM-DD')))} + value={value ? dayjs(value.toString()).format('DD/MM/YYYY') : undefined} + onChange={(evt) => onChange(new Date(evt.target.value))} /> ); diff --git a/src/form-engine.test.tsx b/src/form-engine.test.tsx index 7bfff1fc1..556f4ddfe 100644 --- a/src/form-engine.test.tsx +++ b/src/form-engine.test.tsx @@ -3,10 +3,9 @@ import dayjs from 'dayjs'; import userEvent from '@testing-library/user-event'; import { act, cleanup, render, screen, within, fireEvent, waitFor } from '@testing-library/react'; import { OpenmrsDatePicker, openmrsFetch, restBaseUrl, usePatient, useSession } from '@openmrs/esm-framework'; -import { parseDate } from '@internationalized/date'; import { when } from 'jest-when'; import * as api from '../src/api/api'; -import { assertFormHasAllFields, findMultiSelectInput, findSelectInput } from './utils/test-utils'; +import { assertFormHasAllFields, findMultiSelectInput, findSelectInput, findTextOrDateInput } from './utils/test-utils'; import { evaluatePostSubmissionExpression } from './utils/post-submission-action-helper'; import { mockPatient } from '__mocks__/patient.mock'; import { mockSessionDataResponse } from '__mocks__/session.mock'; @@ -86,8 +85,9 @@ mockOpenmrsDatePicker.mockImplementation( onChange(parseDate(dayjs(evt.target.value).format('YYYY-MM-DD')))} + value={value ? dayjs(value.toString()).format('DD/MM/YYYY') : undefined} + onChange={(evt) => onChange(new Date(evt.target.value))} + role="textbox" /> {isInvalid && invalidText && {invalidText}} @@ -105,7 +105,7 @@ describe('Form engine component', () => { it('should render the form schema without dying', async () => { await act(async () => renderForm(null, htsPocForm)); - await assertFormHasAllFields(screen, [{ fieldName: 'When was the HIV test conducted? *', fieldType: 'date' }]); + await assertFormHasAllFields(screen, [{ fieldName: 'When was the HIV test conducted?', fieldType: 'date' }]); }); it('should render by the form UUID without dying', async () => { @@ -114,7 +114,7 @@ describe('Form engine component', () => { }); await assertFormHasAllFields(screen, [ - { fieldName: 'When was the HIV test conducted? *', fieldType: 'date' }, + { fieldName: 'When was the HIV test conducted?', fieldType: 'date' }, { fieldName: 'Community service delivery point', fieldType: 'select' }, { fieldName: 'TB screening', fieldType: 'combobox' }, ]); @@ -126,7 +126,7 @@ describe('Form engine component', () => { }); await assertFormHasAllFields(screen, [ - { fieldName: 'When was the HIV test conducted? *', fieldType: 'date' }, + { fieldName: 'When was the HIV test conducted?', fieldType: 'date' }, { fieldName: 'TB screening', fieldType: 'combobox' }, ]); @@ -148,7 +148,7 @@ describe('Form engine component', () => { }); await assertFormHasAllFields(screen, [ - { fieldName: 'When was the HIV test conducted? *', fieldType: 'date' }, + { fieldName: 'When was the HIV test conducted?', fieldType: 'date' }, { fieldName: 'Community service delivery point', fieldType: 'combobox' }, ]); @@ -287,14 +287,14 @@ describe('Form engine component', () => { await assertFormHasAllFields(screen, [ { fieldName: 'Was this visit scheduled?', fieldType: 'combobox' }, - { fieldName: 'If Unscheduled, actual text scheduled date *', fieldType: 'text' }, - { fieldName: 'If Unscheduled, actual scheduled date *', fieldType: 'date' }, - { fieldName: 'If Unscheduled, actual number scheduled date *', fieldType: 'number' }, - { fieldName: 'If Unscheduled, actual text area scheduled date *', fieldType: 'textarea' }, + { fieldName: 'If Unscheduled, actual text scheduled date', fieldType: 'text' }, + { fieldName: 'If Unscheduled, actual scheduled date', fieldType: 'date' }, + { fieldName: 'If Unscheduled, actual number scheduled date', fieldType: 'number' }, + { fieldName: 'If Unscheduled, actual text area scheduled date', fieldType: 'textarea' }, { fieldName: 'Not required actual text area scheduled date', fieldType: 'textarea' }, - { fieldName: 'If Unscheduled, actual scheduled reason select *', fieldType: 'select' }, - { fieldName: 'If Unscheduled, actual scheduled reason multi-select *', fieldType: 'combobox' }, - { fieldName: 'If Unscheduled, actual scheduled reason radio *', fieldType: 'radio' }, + { fieldName: 'If Unscheduled, actual scheduled reason select', fieldType: 'select' }, + { fieldName: 'If Unscheduled, actual scheduled reason multi-select', fieldType: 'combobox' }, + { fieldName: 'If Unscheduled, actual scheduled reason radio', fieldType: 'radio' }, ]); // TODO: Temporarily disabling this until the core date picker mock gets fixed