From d2bc72dace4ab77ab7fef3dc603f25c59a4b88f7 Mon Sep 17 00:00:00 2001 From: SagivOnoApps Date: Sun, 26 Apr 2020 14:04:08 +0300 Subject: [PATCH] fix Sample service tests --- src/components/Main/MapModal.tsx | 5 ++--- src/services/__tests__/SampleService.test.ts | 22 +++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/Main/MapModal.tsx b/src/components/Main/MapModal.tsx index 49bca156..2fd830d6 100644 --- a/src/components/Main/MapModal.tsx +++ b/src/components/Main/MapModal.tsx @@ -15,11 +15,10 @@ const MapModal = () => { } = useSelector(state => state.general); const { strings: { - scanHome: { inDate, fromHour, wereYouThere, wasNotMe, wasMe, suspectedExposure, events, possibleExposure, atPlace, showOnMap }, + scanHome: { inDate, fromHour }, }, } = useSelector(state => state.locale); - - + const [date, hour] = useMemo(() => { const time = moment(properties?.fromTime); return [time.format('DD.MM.YY'), time.format('DD.MM.YY')]; diff --git a/src/services/__tests__/SampleService.test.ts b/src/services/__tests__/SampleService.test.ts index ab166188..3e6c404e 100644 --- a/src/services/__tests__/SampleService.test.ts +++ b/src/services/__tests__/SampleService.test.ts @@ -3,15 +3,22 @@ import { startSampling, insertDB, purgeSamplesDB, updateDBAccordingToSampleVeloc import { onError } from '../ErrorService'; import * as db from '../../database/Database'; import { IS_LAST_POINT_FROM_TIMELINE, HIGH_VELOCITY_POINTS } from '../../constants/Constants'; +import {startLocationTracking} from '../LocationService' + jest.mock('../WifiService', () => ({ getWifiList: jest.fn().mockResolvedValue(['ssdid']), })); +jest.mock('../LocationService', () => ({ + startLocationTracking: jest.fn() +})) + beforeEach(() => { onError.mockClear(); db.mockClear(); AsyncStorage.mockClear(); + startLocationTracking.mockClear() }); afterEach(() => { @@ -21,13 +28,22 @@ afterEach(() => { describe('Sample Service', () => { describe('startSampling', () => { test('check resolves', async () => { - // onError.mockImplementationOnce(console.log); - expect(startSampling('en', { androidNotification: {} })).resolves.toBeTruthy(); + startLocationTracking.mockResolvedValueOnce() + await startSampling('en', { androidNotification: {} }) + expect(startLocationTracking).toBeCalledTimes(1) }); test('check resolves for unknown language', async () => { + startLocationTracking.mockResolvedValueOnce() expect(startSampling('ge', { androidNotification: {} })).resolves.toBeTruthy(); + expect(startLocationTracking).toBeCalledTimes(1) }); + + test('startLocationTracking reject', async () => { + startLocationTracking.mockRejectedValueOnce() + expect(startSampling('en', { androidNotification: {} })).rejects.toBeTruthy(); + expect(startLocationTracking).toBeCalledTimes(1) + }) }); describe('insertDB', () => { @@ -104,7 +120,7 @@ describe('Sample Service', () => { // mock IS_LAST_POINT_FROM_TIMELINE await AsyncStorage.setItem(IS_LAST_POINT_FROM_TIMELINE, 'true'); // return insertDB - expect(await updateDBAccordingToSampleVelocity(sample)).toBeTruthy(); + await updateDBAccordingToSampleVelocity(sample) }); test('with one point from DB', async () => {