117 lines
3.2 KiB
TypeScript
117 lines
3.2 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/trk/:trk');
|
|
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/trk/0');
|
|
});
|
|
test(', using the two levels (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx/trk/:trk');
|
|
expect(gpx('gpx/10/trk/0')).toMatchObject({ gpx: '10', trk: '0' });
|
|
});
|
|
});
|
|
|
|
describe('Checking a multilevel route with optional part', () => {
|
|
test(', using the two levels', () => {
|
|
const gpx = route('gpx/:gpx(/trk/:trk)');
|
|
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/trk/0');
|
|
});
|
|
test(', using the two levels (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx(/trk/:trk)');
|
|
expect(gpx('gpx/10/trk/0')).toMatchObject({ gpx: '10', trk: '0' });
|
|
});
|
|
test(', using only one level', () => {
|
|
const gpx = route('gpx/:gpx(/trk/:trk)');
|
|
expect(gpx({ gpx: 10 })).toBe('gpx/10/trk/'); //Unfortunately !
|
|
});
|
|
test(', using only one level (vive-versa)', () => {
|
|
const gpx = route('gpx/:gpx(/trk/:trk)');
|
|
expect(gpx('gpx/10')).toMatchObject({ gpx: '10' });
|
|
});
|
|
});
|
|
|
|
describe('Checking gpx ids', () => {
|
|
test(', vice', () => {
|
|
const gpx = uri('gpx', { gpx: 'id' });
|
|
expect(gpx).toBe('gpx/id');
|
|
});
|
|
test(', and versa', () => {
|
|
const gpx = uri('gpx', 'gpx/id');
|
|
expect(gpx).toMatchObject({ gpx: 'id' });
|
|
});
|
|
});
|
|
|
|
describe('Checking trk ids', () => {
|
|
test(', vice', () => {
|
|
const rte = uri('trk', { gpx: 'gpxid', trk: 'trkid' });
|
|
expect(rte).toBe('gpx/gpxid/trk/trkid');
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trk', 'gpx/gpxid/trk/trkid');
|
|
expect(rte).toMatchObject({ gpx: 'gpxid', trk: 'trkid' });
|
|
});
|
|
});
|
|
|
|
describe('Checking trkseg ids', () => {
|
|
test(', vice', () => {
|
|
const rte = uri('trkseg', {
|
|
gpx: 'gpxid',
|
|
trk: 'trkid',
|
|
trkseg: 'trksegid',
|
|
});
|
|
expect(rte).toBe('gpx/gpxid/trk/trkid/trksegid');
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trkseg', 'gpx/gpxid/trk/trkid/trksegid');
|
|
expect(rte).toMatchObject({
|
|
gpx: 'gpxid',
|
|
trk: 'trkid',
|
|
trkseg: 'trksegid',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Checking trkpt ids', () => {
|
|
test(', vice', () => {
|
|
const rte = uri('trkpt', {
|
|
gpx: 'gpxid',
|
|
trk: 'trkid',
|
|
trkseg: 'trksegid',
|
|
trkpt: 'trkptid',
|
|
});
|
|
expect(rte).toBe('gpx/gpxid/trk/trkid/trksegid/trkptid');
|
|
});
|
|
test(', and versa', () => {
|
|
const rte = uri('trkpt', 'gpx/gpxid/trk/trkid/trksegid/trkptid');
|
|
expect(rte).toMatchObject({
|
|
gpx: 'gpxid',
|
|
trk: 'trkid',
|
|
trkseg: 'trksegid',
|
|
trkpt: 'trkptid',
|
|
});
|
|
});
|
|
});
|
|
|
|
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({});
|
|
});
|
|
});
|