121 lines
3.1 KiB
TypeScript
121 lines
3.1 KiB
TypeScript
import { route } from './docuri';
|
|
import uri from './ids';
|
|
|
|
describe('Checking some DocURI features', () => {
|
|
test(', basic route', () => {
|
|
const gpx = route('gpx/:id');
|
|
expect(gpx({ id: 10 })).toBe('gpx/10');
|
|
});
|
|
test(', basic route (vice-versa', () => {
|
|
const gpx = route('gpx/:id');
|
|
expect(gpx('gpx/10')).toMatchObject({ id: '10' });
|
|
});
|
|
});
|
|
|
|
describe('Checking a multilevel route', () => {
|
|
test(', using the two levels', () => {
|
|
const gpx = route('gpx/:gpx/3trk/:trk');
|
|
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/3trk/0');
|
|
});
|
|
test(', using the two levels (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx/3trk/:trk');
|
|
expect(gpx('gpx/10/3trk/0')).toMatchObject({ gpx: '10', trk: '0' });
|
|
});
|
|
});
|
|
|
|
describe('Checking a multilevel route with optional part', () => {
|
|
test(', using the two levels', () => {
|
|
const gpx = route('gpx/:gpx(/3trk/:trk)');
|
|
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/3trk/0');
|
|
});
|
|
test(', using the two levels (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx(/3trk/:trk)');
|
|
expect(gpx('gpx/10/3trk/0')).toMatchObject({ gpx: '10', trk: '0' });
|
|
});
|
|
test(', using only one level', () => {
|
|
const gpx = route('gpx/:gpx(/3trk/:trk)');
|
|
expect(gpx({ gpx: 10 })).toBe('gpx/10/3trk/'); //Unfortunately !
|
|
});
|
|
test(', using only one level (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx(/3trk/:trk)');
|
|
expect(gpx('gpx/10')).toMatchObject({ gpx: '10' });
|
|
});
|
|
});
|
|
|
|
describe('Checking gpx ids', () => {
|
|
const id = {
|
|
gpx: 1234567890123456,
|
|
};
|
|
const key = 'gpx/1234567890123456';
|
|
test(', vice', () => {
|
|
const gpx = uri('gpx', id);
|
|
expect(gpx).toBe(key);
|
|
});
|
|
test(', and versa', () => {
|
|
const gpx = uri('gpx', key);
|
|
expect(gpx).toMatchObject(id);
|
|
});
|
|
});
|
|
|
|
describe('Checking trk ids', () => {
|
|
const id = {
|
|
gpx: 1234567890123456,
|
|
trk: 123456,
|
|
};
|
|
const key = 'gpx/1234567890123456/3trk/123456';
|
|
test(', vice', () => {
|
|
const rte = uri('trk', id);
|
|
expect(rte).toBe(key);
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trk', key);
|
|
expect(rte).toMatchObject(id);
|
|
});
|
|
});
|
|
|
|
describe('Checking trkseg ids', () => {
|
|
const id = {
|
|
gpx: 111,
|
|
trk: 0,
|
|
trkseg: 3,
|
|
};
|
|
const key = 'gpx/0000000000000111/3trk/000000/000003';
|
|
test(', vice', () => {
|
|
const rte = uri('trkseg', id);
|
|
expect(rte).toBe(key);
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trkseg', key);
|
|
expect(rte).toMatchObject(id);
|
|
});
|
|
});
|
|
|
|
describe('Checking trkpt ids', () => {
|
|
const id = {
|
|
gpx: 25,
|
|
trk: 8,
|
|
trkseg: 0,
|
|
trkpt: 155,
|
|
};
|
|
const key = 'gpx/0000000000000025/3trk/000008/000000/000155';
|
|
test(', vice', () => {
|
|
const rte = uri('trkpt', id);
|
|
expect(rte).toBe(key);
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trkpt', key);
|
|
expect(rte).toMatchObject(id);
|
|
});
|
|
});
|
|
|
|
describe('Checking settings id', () => {
|
|
test(', vice', () => {
|
|
const rte = uri('settings', {});
|
|
expect(rte).toBe('settings');
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('settings', 'settings');
|
|
expect(rte).toMatchObject({});
|
|
});
|
|
});
|