-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic test for loading composite trips into the timeline. Mocks a unified query response with 3 composite trips. Then checks to make sure those 3 trips can be rendered in a dummy component by reading 'timelineMap'. in timelineHelper.ts, do not attempt to unpack server data that doesn't exist (added because start_confirmed_place and end_confirmed_place don't exist on the dummy trips used for testing) In cordovaMocks.ts, resolve with [] instead of returning undefined
- Loading branch information
Showing
3 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useEffect } from 'react'; | ||
import { View, Text } from 'react-native'; | ||
import { act, render, screen, waitFor } from '@testing-library/react-native'; | ||
import { useTimelineContext } from '../js/TimelineContext'; | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import { mockBEMServerCom, mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
|
||
mockLogger(); | ||
mockBEMUserCache(); | ||
|
||
jest.mock('../js/services/commHelper', () => ({ | ||
getPipelineRangeTs: jest.fn(() => Promise.resolve({ start_ts: 1, end_ts: 10 })), | ||
getRawEntries: jest.fn((key_list, _, __) => { | ||
let phone_data: any[] = []; | ||
if (key_list.includes('analysis/composite_trip')) { | ||
phone_data = [ | ||
{ | ||
_id: { $oid: 'trip1' }, | ||
metadata: { write_ts: 1, origin_key: 'analysis/confirmed_trip' }, | ||
data: { start_ts: 1, end_ts: 2 }, | ||
}, | ||
{ | ||
_id: { $oid: 'trip2' }, | ||
metadata: { write_ts: 2, origin_key: 'analysis/confirmed_trip' }, | ||
data: { start_ts: 3, end_ts: 4 }, | ||
}, | ||
{ | ||
_id: { $oid: 'trip3' }, | ||
metadata: { write_ts: 3, origin_key: 'analysis/confirmed_trip' }, | ||
data: { start_ts: 5, end_ts: 6 }, | ||
}, | ||
]; | ||
} | ||
return Promise.resolve({ phone_data }); | ||
}), | ||
fetchUrlCached: jest.fn(() => Promise.resolve(null)), | ||
})); | ||
|
||
// Mock useAppConfig default export | ||
jest.mock('../js/useAppConfig', () => { | ||
return jest.fn(() => ({ intro: {} })); | ||
}); | ||
|
||
const TimelineContextTestComponent = () => { | ||
const { timelineMap, setDateRange } = useTimelineContext(); | ||
|
||
useEffect(() => { | ||
// setDateRange(['2021-01-01', '2021-01-07']); | ||
}, []); | ||
|
||
if (!timelineMap) return null; | ||
|
||
console.debug('timelineMap', timelineMap); | ||
|
||
return ( | ||
<View testID="timeline-entries"> | ||
{[...timelineMap.values()].map((entry, i) => ( | ||
<Text key={i}>{'entry ID: ' + entry._id.$oid}</Text> | ||
))} | ||
</View> | ||
); | ||
}; | ||
|
||
describe('TimelineContext', () => { | ||
it('renders correctly', async () => { | ||
render(<TimelineContextTestComponent />); | ||
await waitFor(() => { | ||
// make sure timeline entries are rendered | ||
expect(screen.getByTestId('timeline-entries')).toBeTruthy(); | ||
// make sure number of Text components matches number of timeline entries | ||
expect(screen.getAllByText(/entry ID:/).length).toBe(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters