diff --git a/www/__mocks__/globalMocks.ts b/www/__mocks__/globalMocks.ts index f13cb274b..62ea1b935 100644 --- a/www/__mocks__/globalMocks.ts +++ b/www/__mocks__/globalMocks.ts @@ -1,3 +1,19 @@ export const mockLogger = () => { window['Logger'] = { log: console.log }; }; + +let alerts = []; + +export const mockAlert = () => { + window['alert'] = (message) => { + alerts.push(message); + }; +}; + +export const clearAlerts = () => { + alerts = []; +}; + +export const getAlerts = () => { + return alerts; +}; diff --git a/www/__mocks__/timelineHelperMocks.ts b/www/__mocks__/timelineHelperMocks.ts index eb9bc834c..53d687968 100644 --- a/www/__mocks__/timelineHelperMocks.ts +++ b/www/__mocks__/timelineHelperMocks.ts @@ -109,3 +109,80 @@ export const fakeStartTsOne = -14576291; export const fakeEndTsOne = -13885091; export const fakeStartTsTwo = 1092844665; export const fakeEndTsTwo = 1277049465; + +export const readAllCheck = [ + { + ...mockData.phone_data[0].data, + }, +]; + +export const readAllCompositeCheck = [ + { + additions: [], + cleaned_section_summary: null, + cleaned_trip: null, + confidence_threshold: -1, + confirmed_trip: null, + distance: 777, + duration: 777, + end_confirmed_place: { + key: 'test/value', + origin_key: '12345', + }, + end_fmt_time: '2023-11-01T17:55:20.999397-07:00', + end_loc: { + type: 'Point', + coordinates: [-1, -1], + }, + end_local_dt: null, + end_place: null, + end_ts: -1, + expectation: null, + expected_trip: null, + inferred_labels: [], + inferred_section_summary: { + count: { + CAR: 1, + WALKING: 1, + }, + distance: { + CAR: 222, + WALKING: 222, + }, + duration: { + CAR: 333, + WALKING: 333, + }, + }, + inferred_trip: null, + key: 'test/value', + locations: [ + { + key: 'test/value', + origin_key: '12345', + }, + ], + origin_key: '12345', + raw_trip: null, + sections: [ + { + key: 'test/value', + origin_key: '12345', + }, + ], + source: 'DwellSegmentationDistFilter', + start_confirmed_place: { + key: 'test/value', + origin_key: '12345', + }, + start_fmt_time: '2023-11-01T17:55:20.999397-07:00', + start_loc: { + type: 'Point', + coordinates: [-1, -1], + }, + start_local_dt: null, + start_place: null, + start_ts: null, + user_input: null, + }, +]; diff --git a/www/__tests__/timelineHelper.test.ts b/www/__tests__/timelineHelper.test.ts index 0faac2c2e..e0f424fcf 100644 --- a/www/__tests__/timelineHelper.test.ts +++ b/www/__tests__/timelineHelper.test.ts @@ -1,12 +1,17 @@ -import { mockLogger } from '../__mocks__/globalMocks'; +import { clearAlerts, mockAlert, mockLogger } from '../__mocks__/globalMocks'; import { readAllCompositeTrips, readUnprocessedTrips } from '../js/diary/timelineHelper'; import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; import * as mockTLH from '../__mocks__/timelineHelperMocks'; mockLogger(); +mockAlert(); mockBEMUserCache(); +beforeEach(() => { + clearAlerts(); +}); + afterAll(() => { jest.restoreAllMocks(); }); @@ -21,13 +26,13 @@ jest.mock('../js/commHelper', () => ({ })); it('works when there are no composite trip objects fetched', async () => { - expect(readAllCompositeTrips(-1, -1)).resolves.not.toThrow(); + expect(readAllCompositeTrips(-1, -1)).resolves.toEqual([]); }); it('fetches a composite trip object and collapses it', async () => { - expect( - readAllCompositeTrips(mockTLH.fakeStartTsOne, mockTLH.fakeEndTsOne), - ).resolves.not.toThrow(); + expect(readAllCompositeTrips(mockTLH.fakeStartTsOne, mockTLH.fakeEndTsOne)).resolves.toEqual( + mockTLH.readAllCompositeCheck, + ); expect( readAllCompositeTrips(mockTLH.fakeStartTsTwo, mockTLH.fakeEndTsTwo), ).resolves.not.toThrow();