Cleanup and starting to implements tracks.

This commit is contained in:
vdv committed 2022-11-07 22:12:50 +01:00
1 parent 36a3199b36
commit 26486b65b9
9 files changed
+225 -26

No files matched your search

+14 -12
View File
@@ -7,19 +7,17 @@ declare global {
const originalDb = globalThis.db;
const originalDateNow = globalThis.Date.now;
beforeEach(() => {
globalThis.db = { put: jest.fn() };
globalThis.Date.now = () => 0;
});
afterEach(() => {
globalThis.db = originalDb;
globalThis.Date.now = originalDateNow;
});
describe('The gpx module', () => {
beforeEach(() => {
globalThis.db = { put: jest.fn() };
globalThis.Date.now = () => 0;
});
afterEach(() => {
globalThis.db = originalDb;
globalThis.Date.now = originalDateNow;
});
test('db.put() a new Gpx when required', () => {
putNewGpx('whatever');
putNewGpx({ gpx: 'whatever' });
expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/whatever',
doc: {
@@ -45,7 +43,7 @@ describe('The gpx module', () => {
desc: '',
extensions: '',
keywords: '',
link: '',
link: [],
name: '',
time: '1970-01-01T00:00:00.000Z',
},
@@ -56,4 +54,8 @@ describe('The gpx module', () => {
type: 'gpx',
});
});
test('db.put() generates an id if needed', () => {
const id = putNewGpx();
expect(id).toEqual({ gpx: '0' });
});
});
+4 -3
View File
@@ -19,7 +19,7 @@ const emptyGpx: Gpx = {
desc: '',
author: '',
copyright: '',
link: '',
link: [],
time: '',
keywords: '',
bounds: '',
@@ -31,8 +31,8 @@ const emptyGpx: Gpx = {
extensions: '',
};
export const putNewGpx = (id: string) => {
const uri = getUri('gpx', { gpx: id });
export const putNewGpx = (id: IdGpx = { gpx: Date.now().toString() }) => {
const uri = getUri('gpx', id);
put(
uri,
'gpx',
@@ -42,4 +42,5 @@ export const putNewGpx = (id: string) => {
},
emptyGpx
);
return id;
};
+15
View File
@@ -0,0 +1,15 @@
import getUri from '../lib/ids';
import { put } from './lib';
const emptyTrk: Trk = {
name: '',
cmt: '',
desc: '',
src: '',
link: [],
number: 0,
type: '',
extensions: {},
trkseg: [],
};
+24 -2
View File
@@ -3,7 +3,7 @@ interface Gpx {
metadata?: Metadata;
wpt?: any[];
rte?: any[];
trk?: any[];
trk?: Trk[];
extensions?: Extensions;
}
@@ -24,7 +24,7 @@ interface Metadata {
desc?: string;
author?: string;
copyright?: string;
link?: string;
link?: Link[];
time?: string;
keywords?: string;
bounds?: string;
@@ -32,3 +32,25 @@ interface Metadata {
}
interface Extensions {}
interface Trk {
name?: string;
cmt?: string;
desc?: string;
src?: string;
link?: Link[];
number?: number;
type?: string;
extensions?: Extensions;
trkseg?: any[];
}
interface Link {
$: Link_;
text?: string;
type?: string;
}
interface Link_ {
href: string;
}