import { putNewRte } from './rte'; import { putNewTrk } from './trk'; declare global { var db: any; var dbReady: boolean; } const originalDb = globalThis.db; const originalDateNow = globalThis.Date.now; describe('The rte module', () => { beforeEach(() => { globalThis.db = { put: jest.fn() }; globalThis.Date.now = () => 0; }); afterEach(() => { globalThis.db = originalDb; globalThis.Date.now = originalDateNow; }); test('db.put() a new rte when required', async () => { putNewRte({ gpx: 'gpxId', rte: 'rteid' }); await expect(globalThis.db.put).toBeCalledWith({ _id: 'gpx/gpxId/1rte/rteid', _rev: undefined, doc: { cmt: undefined, desc: undefined, extensions: undefined, link: undefined, name: undefined, number: 0, src: undefined, trkseg: undefined, type: undefined, }, type: 'rte', }); }); test('db.put() generates an id for the trk if needed', async () => { const id = await putNewRte({ gpx: 'gpxId' }); expect(id).toEqual({ gpx: 'gpxId', rte: '00000' }); }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewRte(); expect(id).toEqual({ gpx: '0', rte: '00000' }); }); });