|
| 1 | +import { isSameRoute, isIncludedRoute } from '../../../src/util/route' |
| 2 | + |
| 3 | +describe('Route utils', () => { |
| 4 | + describe('isSameRoute', () => { |
| 5 | + it('path', () => { |
| 6 | + const a = { |
| 7 | + path: '/a', |
| 8 | + hash: '#hi', |
| 9 | + query: { foo: 'bar', arr: [1, 2] } |
| 10 | + } |
| 11 | + const b = { |
| 12 | + path: '/a', |
| 13 | + hash: '#hi', |
| 14 | + query: { arr: ['1', '2'], foo: 'bar' } |
| 15 | + } |
| 16 | + expect(isSameRoute(a, b)).toBe(true) |
| 17 | + }) |
| 18 | + |
| 19 | + it('name', () => { |
| 20 | + const a = { |
| 21 | + path: '/abc', |
| 22 | + name: 'a', |
| 23 | + hash: '#hi', |
| 24 | + query: { foo: 'bar', arr: [1, 2] } |
| 25 | + } |
| 26 | + const b = { |
| 27 | + name: 'a', |
| 28 | + hash: '#hi', |
| 29 | + query: { arr: ['1', '2'], foo: 'bar' } |
| 30 | + } |
| 31 | + expect(isSameRoute(a, b)).toBe(true) |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + describe('isIncludedRoute', () => { |
| 36 | + it('path', () => { |
| 37 | + const a = { path: '/a/b' } |
| 38 | + const b = { path: '/a' } |
| 39 | + const c = { path: '/a/b/c' } |
| 40 | + expect(isIncludedRoute(a, b)).toBe(true) |
| 41 | + expect(isIncludedRoute(a, c)).toBe(false) |
| 42 | + }) |
| 43 | + |
| 44 | + it('with hash', () => { |
| 45 | + const a = { path: '/a/b', hash: '#a' } |
| 46 | + const b = { path: '/a' } |
| 47 | + const c = { path: '/a', hash: '#a' } |
| 48 | + const d = { path: '/a', hash: '#b' } |
| 49 | + expect(isIncludedRoute(a, b)).toBe(true) |
| 50 | + expect(isIncludedRoute(a, c)).toBe(true) |
| 51 | + expect(isIncludedRoute(a, d)).toBe(false) |
| 52 | + }) |
| 53 | + |
| 54 | + it('with query', () => { |
| 55 | + const a = { path: '/a/b', query: { foo: 'bar', baz: 'qux' }} |
| 56 | + const b = { path: '/a', query: {}} |
| 57 | + const c = { path: '/a', query: { foo: 'bar' }} |
| 58 | + const d = { path: '/a', query: { foo: 'bar', a: 'b' }} |
| 59 | + expect(isIncludedRoute(a, b)).toBe(true) |
| 60 | + expect(isIncludedRoute(a, c)).toBe(true) |
| 61 | + expect(isIncludedRoute(a, d)).toBe(false) |
| 62 | + }) |
| 63 | + |
| 64 | + it('with both', () => { |
| 65 | + const a = { path: '/a/b', query: { foo: 'bar', baz: 'qux' }, hash: '#a' } |
| 66 | + const b = { path: '/a', query: {}} |
| 67 | + const c = { path: '/a', query: { foo: 'bar' }} |
| 68 | + const d = { path: '/a', query: { foo: 'bar' }, hash: '#b' } |
| 69 | + const e = { path: '/a', query: { a: 'b' }, hash: '#a' } |
| 70 | + expect(isIncludedRoute(a, b)).toBe(true) |
| 71 | + expect(isIncludedRoute(a, c)).toBe(true) |
| 72 | + expect(isIncludedRoute(a, d)).toBe(false) |
| 73 | + expect(isIncludedRoute(a, e)).toBe(false) |
| 74 | + }) |
| 75 | + }) |
| 76 | +}) |
0 commit comments