From 5105da0d29dad389156ac6ac7b24eddcc81e04e4 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 21 Aug 2023 12:49:31 -0400 Subject: [PATCH] (fix) Fix some tests with implicit environment assumptions Mostly this relates to local time being only slightly > UTC --- src/hooks/useInitialValues.test.ts | 11 ++++++----- src/ohri-form.component.test.tsx | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/hooks/useInitialValues.test.ts b/src/hooks/useInitialValues.test.ts index cf61d3c6..6b3d93e2 100644 --- a/src/hooks/useInitialValues.test.ts +++ b/src/hooks/useInitialValues.test.ts @@ -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; }); }); @@ -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(); @@ -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', }); }); diff --git a/src/ohri-form.component.test.tsx b/src/ohri-form.component.test.tsx index e14ede63..7ef12d66 100644 --- a/src/ohri-form.component.test.tsx +++ b/src/ohri-form.component.test.tsx @@ -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 () => { @@ -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')); }); @@ -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()); });