Waypoints
This commit is contained in:
parent
16ca39a160
commit
1b9c7fc261
|
@ -4,6 +4,7 @@ import { getFamily } from './lib';
|
|||
import { putNewTrk } from './trk';
|
||||
import { putNewTrkpt } from './trkpt';
|
||||
import { putNewTrkseg } from './trkseg';
|
||||
import { putNewWpt } from './wpt';
|
||||
|
||||
declare global {
|
||||
var db: any;
|
||||
|
@ -175,6 +176,33 @@ Object {
|
|||
],
|
||||
"total_rows": 7,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('returns two rows after a gpx and a waypoint have been inserted.', async () => {
|
||||
await putNewWpt();
|
||||
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
|
||||
expect(allDocs).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"offset": 0,
|
||||
"rows": Array [
|
||||
Object {
|
||||
"id": "gpx/0",
|
||||
"key": "gpx/0",
|
||||
"value": Object {
|
||||
"rev": "1-98d42c99fcf471a500b0506a60e77559",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"id": "gpx/0/0wpt/00000",
|
||||
"key": "gpx/0/0wpt/00000",
|
||||
"value": Object {
|
||||
"rev": "1-dcdc55abd413b401dba4278510d9c51b",
|
||||
},
|
||||
},
|
||||
],
|
||||
"total_rows": 5,
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -86,7 +86,7 @@ interface Wpt {
|
|||
pdop?: number;
|
||||
ageofdgpsdata?: number;
|
||||
dgpsid?: number;
|
||||
extensions: Extensions;
|
||||
extensions?: Extensions;
|
||||
}
|
||||
|
||||
interface Trkpt_ {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
import { putNewWpt } from './wpt';
|
||||
|
||||
declare global {
|
||||
var db: any;
|
||||
var dbReady: boolean;
|
||||
}
|
||||
|
||||
const originalDb = globalThis.db;
|
||||
const originalDateNow = globalThis.Date.now;
|
||||
|
||||
describe('The wpt module', () => {
|
||||
beforeEach(() => {
|
||||
globalThis.db = { put: jest.fn() };
|
||||
globalThis.Date.now = () => 0;
|
||||
});
|
||||
afterEach(() => {
|
||||
globalThis.db = originalDb;
|
||||
globalThis.Date.now = originalDateNow;
|
||||
});
|
||||
test('db.put() a new wpt when required', async () => {
|
||||
putNewWpt({ gpx: 'gpxId', wpt: 'wptid' });
|
||||
await expect(globalThis.db.put).toBeCalledWith({
|
||||
_id: 'gpx/gpxId/0wpt/wptid',
|
||||
_rev: undefined,
|
||||
doc: {
|
||||
$: { lat: 0, lon: 0 },
|
||||
ageofdgpsdata: undefined,
|
||||
cmt: undefined,
|
||||
desc: undefined,
|
||||
dgpsid: undefined,
|
||||
ele: undefined,
|
||||
extensions: undefined,
|
||||
fix: undefined,
|
||||
geoidheight: undefined,
|
||||
hdop: undefined,
|
||||
link: undefined,
|
||||
magvar: undefined,
|
||||
name: undefined,
|
||||
pdop: undefined,
|
||||
sat: undefined,
|
||||
src: undefined,
|
||||
sym: undefined,
|
||||
time: undefined,
|
||||
type: undefined,
|
||||
vdop: undefined,
|
||||
},
|
||||
type: 'wpt',
|
||||
});
|
||||
});
|
||||
test('db.put() generates an id for the wpt if needed', async () => {
|
||||
const id = await putNewWpt({ gpx: 'gpxId' });
|
||||
expect(id).toEqual({ gpx: 'gpxId', wpt: '00000' });
|
||||
});
|
||||
test('db.put() generates ids for both gpx and trk if needed', async () => {
|
||||
const id = await putNewWpt();
|
||||
expect(id).toEqual({ gpx: '0', wpt: '00000' });
|
||||
});
|
||||
});
|
|
@ -0,0 +1,44 @@
|
|||
import getUri from '../lib/ids';
|
||||
import { putNewGpx } from './gpx';
|
||||
import { put } from './lib';
|
||||
|
||||
export const emptyWpt: Wpt = {
|
||||
$: { lat: 0, lon: 0 },
|
||||
ele: undefined,
|
||||
time: undefined,
|
||||
magvar: undefined,
|
||||
geoidheight: undefined,
|
||||
name: undefined,
|
||||
cmt: undefined,
|
||||
desc: undefined,
|
||||
src: undefined,
|
||||
link: undefined,
|
||||
sym: undefined,
|
||||
type: undefined,
|
||||
fix: undefined,
|
||||
sat: undefined,
|
||||
hdop: undefined,
|
||||
vdop: undefined,
|
||||
pdop: undefined,
|
||||
ageofdgpsdata: undefined,
|
||||
dgpsid: undefined,
|
||||
extensions: undefined,
|
||||
};
|
||||
|
||||
export const putNewWpt = async (id?: IdGpx | IdWpt) => {
|
||||
let finalId = { ...id };
|
||||
if (!('wpt' in finalId)) {
|
||||
const gpxId = await putNewGpx(id);
|
||||
finalId = { ...gpxId, wpt: '00000' };
|
||||
}
|
||||
const uri = getUri('wpt', finalId);
|
||||
await put(
|
||||
uri,
|
||||
'wpt',
|
||||
(wpt) => {
|
||||
return wpt;
|
||||
},
|
||||
emptyWpt
|
||||
);
|
||||
return finalId as IdWpt;
|
||||
};
|
Loading…
Reference in New Issue