From 61290b1f35f9efe9c814f209b6d3a37e110a1e7f Mon Sep 17 00:00:00 2001 From: gheoan Date: Wed, 27 Sep 2017 23:00:14 +0300 Subject: [PATCH] test(router): test multiple identical patterns --- test/router.spec.js | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/router.spec.js b/test/router.spec.js index 793de308..40db7dcb 100644 --- a/test/router.spec.js +++ b/test/router.spec.js @@ -239,6 +239,53 @@ describe('the router', () => { .then(done); }); + describe('should match routes with same pattern based on href', () => { + it('', (done) => { + router.configure(config => config.map([ + { name: 'a', route: 'test/:p', moduleId: './test', href: '/test/a' }, + { name: 'b', route: 'test/:p', moduleId: './test', href: '/test/b' } + ])) + .then(() => router._createNavigationInstruction('test/b?foo=456')) + .then(i => { + expect(i.fragment).toEqual('test/b'); + expect(i.queryString).toEqual('foo=456'); + expect(i.params.p).toEqual('b'); + expect(i.config.name).toEqual('b'); + }) + .catch(reason => fail(reason)) + .then(done); + }); + + it('when fragment matches the child router', (done) => { + const childRouter = router.createChild(new Container()); + + router.configure(config => config.map([ + { name: 'a', route: 'parent/:p', moduleId: './parent', href: '/parent/a' }, + { name: 'b', route: 'parent/:p', moduleId: './parent', href: '/parent/b' } + ])) + .then(() => childRouter.configure(config => config.map([ + { name: 'c', route: 'child/:p', moduleId: './child', href: '/child/c' }, + { name: 'd', route: 'child/:p', moduleId: './child', href: '/child/d' }, + ]))) + .then(() => router._createNavigationInstruction('parent/b/child/c?foo=456')) + .then(i => { + expect(i.fragment).toEqual('parent/b/child/c'); + expect(i.queryString).toEqual('foo=456'); + expect(i.params.p).toEqual('b'); + expect(i.config.name).toEqual('b'); + }) + .then(() => childRouter._createNavigationInstruction('child/c?foo=456')) + .then(i => { + expect(i.fragment).toEqual('child/c'); + expect(i.queryString).toEqual('foo=456'); + expect(i.params.p).toEqual('c'); + expect(i.config.name).toEqual('c'); + }) + .catch(reason => fail(reason)) + .then(done); + }); + }); + it('should be case insensitive by default', (done) => { router.configure(config => config.map({ name: 'test', route: 'test/:id', moduleId: './test' })) .then(() => router._createNavigationInstruction('TeSt/123?foo=456'))