2022-11-07 15:38:44 +00:00
|
|
|
import { putNewGpx } from './gpx';
|
|
|
|
declare global {
|
|
|
|
var db: any;
|
|
|
|
var dbReady: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const originalDb = globalThis.db;
|
|
|
|
const originalDateNow = globalThis.Date.now;
|
|
|
|
|
|
|
|
describe('The gpx module', () => {
|
2022-11-07 21:12:50 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
globalThis.db = { put: jest.fn() };
|
|
|
|
globalThis.Date.now = () => 0;
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
globalThis.db = originalDb;
|
|
|
|
globalThis.Date.now = originalDateNow;
|
|
|
|
});
|
2022-11-08 13:16:23 +00:00
|
|
|
test('db.put() a new Gpx when required', async () => {
|
|
|
|
await putNewGpx({ gpx: 'whatever' });
|
2022-11-07 15:38:44 +00:00
|
|
|
expect(globalThis.db.put).toBeCalledWith({
|
|
|
|
_id: 'gpx/whatever',
|
2022-11-08 13:16:23 +00:00
|
|
|
_rev: undefined,
|
2022-11-07 15:38:44 +00:00
|
|
|
doc: {
|
|
|
|
$: {
|
|
|
|
creator: 'dyomedea version 0.000002',
|
|
|
|
version: '1.1',
|
|
|
|
xmlns: 'http://www.topografix.com/GPX/1/1',
|
|
|
|
'xmlns:dyo': 'http://xmlns.dyomedea.com/',
|
|
|
|
'xmlns:gpxtpx':
|
|
|
|
'http://www.garmin.com/xmlschemas/TrackPointExtension/v1',
|
|
|
|
'xmlns:gpxx': 'http://www.garmin.com/xmlschemas/GpxExtensions/v3',
|
|
|
|
'xmlns:wptx1':
|
|
|
|
'http://www.garmin.com/xmlschemas/WaypointExtension/v1',
|
|
|
|
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
|
|
'xsi:schemaLocation':
|
|
|
|
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd',
|
|
|
|
},
|
2022-11-08 13:16:23 +00:00
|
|
|
extensions: undefined,
|
2022-11-07 15:38:44 +00:00
|
|
|
metadata: {
|
2022-11-08 13:16:23 +00:00
|
|
|
author: undefined,
|
|
|
|
bounds: undefined,
|
|
|
|
copyright: undefined,
|
|
|
|
desc: undefined,
|
|
|
|
extensions: undefined,
|
|
|
|
keywords: undefined,
|
|
|
|
link: undefined,
|
|
|
|
name: undefined,
|
2022-11-07 15:38:44 +00:00
|
|
|
time: '1970-01-01T00:00:00.000Z',
|
|
|
|
},
|
2022-11-08 13:16:23 +00:00
|
|
|
rte: undefined,
|
|
|
|
trk: undefined,
|
|
|
|
wpt: undefined,
|
2022-11-07 15:38:44 +00:00
|
|
|
},
|
|
|
|
type: 'gpx',
|
|
|
|
});
|
|
|
|
});
|
2022-11-08 13:16:23 +00:00
|
|
|
test('db.put() generates an id if needed', async () => {
|
|
|
|
const id = await putNewGpx();
|
2022-11-09 09:32:06 +00:00
|
|
|
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z' });
|
2022-11-07 21:12:50 +00:00
|
|
|
});
|
2022-11-07 15:38:44 +00:00
|
|
|
});
|