Skip to content

Commit

Permalink
(fix) Fix some tests with implicit environment assumptions
Browse files Browse the repository at this point in the history
Mostly this relates to local time being only slightly > UTC
  • Loading branch information
ibacher committed Aug 21, 2023
1 parent f8f14e6 commit 5105da0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/hooks/useInitialValues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ jest.mock('../utils/expression-runner', () => {
};
});

describe('useInialValues', () => {
describe('useInitialValues', () => {
const encounterDate = new Date();

afterEach(() => {
allFormFields = allFormFields.slice(0, 6);
allFormFields.forEach(field => {
allFormFields.slice(0, 6).forEach(field => {
delete field.value;
});
});
Expand Down Expand Up @@ -182,10 +181,10 @@ describe('useInialValues', () => {
notes: 'Mother is in perfect condition',
screening_methods: [],
// child one
date_of_birth: '7/24/2023',
date_of_birth: new Date('2023-07-24T00:00:00.000+0000').toLocaleDateString('en-US'),
infant_name: 'TBD',
// child two
date_of_birth_1: '7/24/2023',
date_of_birth_1: new Date('2023-07-24T00:00:00.000+0000').toLocaleDateString('en-US'),
infant_name_1: ' TDB II',
});
expect(allFormFields.find(field => field.id === 'date_of_birth_1')).not.toBeNull();
Expand Down Expand Up @@ -231,7 +230,9 @@ describe('useInialValues', () => {
notes: '',
screening_methods: [],
date_of_birth: '',
date_of_birth_1: '',
infant_name: '',
infant_name_1: '',
latest_mother_hiv_status: '664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/ohri-form.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ describe('OHRI Forms:', () => {
fireEvent.change(lmpField, { target: { value: '2022-07-06' } });

// verify
await act(async () => expect(lmpField.value).toBe('7/6/2022'));
await act(async () => expect(eddField.value).toBe('4/12/2023'));
await act(async () => expect(lmpField.value).toBe(new Date('2022-07-06').toLocaleDateString('en-US')));
await act(async () => expect(eddField.value).toBe(new Date('2023-04-12').toLocaleDateString('en-US')));
});

it('Should evaluate months on ART', async () => {
Expand All @@ -244,7 +244,7 @@ describe('OHRI Forms:', () => {
fireEvent.blur(artStartDateField, { target: { value: '05/02/2022' } });

// verify
await act(async () => expect(artStartDateField.value).toBe('5/2/2022'));
await act(async () => expect(artStartDateField.value).toBe(new Date('2022-05-02T00:00:00.000+0000').toLocaleDateString('en-US')));
await act(async () => expect(assumeTodayToBe).toBe('7/11/2022'));
await act(async () => expect(monthsOnARTField.value).toBe('5'));
});
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('OHRI Forms:', () => {
await act(async () => expect(mrn.value).toBe(''));

// verify
await act(async () => expect(enrollmentDate.value).toBe('7/6/1975'));
await act(async () => expect(enrollmentDate.value).toBe(new Date('1975-07-06T00:00:00.000Z').toLocaleDateString('en-US')));
await act(async () => expect(mrn.value).toBe(''));
await act(async () => expect(mrn).toBeVisible());
});
Expand Down

0 comments on commit 5105da0

Please sign in to comment.