Skip to content

Commit

Permalink
(chore): update datepicker mock
Browse files Browse the repository at this point in the history
  • Loading branch information
NethmiRodrigo authored and denniskigen committed Aug 2, 2024
1 parent 93078d6 commit 965e851
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/components/inputs/unspecified/unspecified.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,8 +17,8 @@ mockOpenmrsDatePicker.mockImplementation(({ id, labelText, value, onChange }) =>
<label htmlFor={id}>{labelText}</label>
<input
id={id}
value={value ? dayjs(value).format('DD/MM/YYYY') : undefined}
onChange={(evt) => 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))}
/>
</>
);
Expand Down
30 changes: 15 additions & 15 deletions src/form-engine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -86,8 +85,9 @@ mockOpenmrsDatePicker.mockImplementation(
<label htmlFor={id}>{labelText}</label>
<input
id={id}
value={value ? dayjs(value).format('DD/MM/YYYY') : undefined}
onChange={(evt) => 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 && <span>{invalidText}</span>}
</>
Expand All @@ -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 () => {
Expand All @@ -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' },
]);
Expand All @@ -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' },
]);

Expand All @@ -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' },
]);

Expand Down Expand Up @@ -292,14 +292,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
Expand Down

0 comments on commit 965e851

Please sign in to comment.