2022-01-05 10:41:29 +01:00
|
|
|
import { splitPath, getPattern, getPathFromURL } from '../src/util'
|
2021-12-26 19:53:44 +01:00
|
|
|
|
|
|
|
describe('Utility methods', () => {
|
|
|
|
it('splitPath', () => {
|
|
|
|
let ps = splitPath('/')
|
|
|
|
expect(ps[0]).toBe('')
|
|
|
|
ps = splitPath('/hello')
|
|
|
|
expect(ps[0]).toBe('hello')
|
|
|
|
ps = splitPath('*')
|
|
|
|
expect(ps[0]).toBe('*')
|
|
|
|
ps = splitPath('/wildcard-abc/*/wildcard-efg')
|
|
|
|
expect(ps[0]).toBe('wildcard-abc')
|
|
|
|
expect(ps[1]).toBe('*')
|
|
|
|
expect(ps[2]).toBe('wildcard-efg')
|
2021-12-27 04:12:22 +01:00
|
|
|
ps = splitPath('/map/:location/events')
|
|
|
|
expect(ps[0]).toBe('map')
|
|
|
|
expect(ps[1]).toBe(':location')
|
|
|
|
expect(ps[2]).toBe('events')
|
2021-12-26 19:53:44 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('getPattern', () => {
|
|
|
|
let res = getPattern(':id')
|
2022-01-05 10:41:29 +01:00
|
|
|
expect(res).not.toBeNull()
|
2021-12-27 06:38:51 +01:00
|
|
|
expect(res[0]).toBe('id')
|
|
|
|
expect(res[1]).toBe('(.+)')
|
2021-12-26 19:53:44 +01:00
|
|
|
res = getPattern(':id{[0-9]+}')
|
2021-12-27 06:38:51 +01:00
|
|
|
expect(res[0]).toBe('id')
|
|
|
|
expect(res[1]).toBe('([0-9]+)')
|
2021-12-26 19:53:44 +01:00
|
|
|
})
|
2022-01-01 13:56:41 +01:00
|
|
|
|
|
|
|
it('getPathFromURL', () => {
|
|
|
|
let path = getPathFromURL('https://example.com/')
|
|
|
|
expect(path).toBe('/')
|
|
|
|
path = getPathFromURL('https://example.com/hello')
|
|
|
|
expect(path).toBe('/hello')
|
|
|
|
path = getPathFromURL('https://example.com/hello/hey')
|
|
|
|
expect(path).toBe('/hello/hey')
|
|
|
|
path = getPathFromURL('https://example.com/hello?name=foo')
|
|
|
|
expect(path).toBe('/hello')
|
|
|
|
path = getPathFromURL('https://example.com/hello/hey?name=foo&name=bar')
|
|
|
|
expect(path).toBe('/hello/hey')
|
|
|
|
path = getPathFromURL('https://example.com/hello/hey#fragment')
|
|
|
|
expect(path).toBe('/hello/hey')
|
|
|
|
})
|
2021-12-26 19:53:44 +01:00
|
|
|
})
|