From 490ef54bbe5de03c6e71cf8b2c6f93fd4ca785bb Mon Sep 17 00:00:00 2001 From: Songissimo Date: Fri, 17 May 2019 09:01:48 +0200 Subject: [PATCH 1/2] Update dsr.ts DSR using params subset redirecting to the default state --- src/dsr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsr.ts b/src/dsr.ts index 38ec9f57..873bf018 100644 --- a/src/dsr.ts +++ b/src/dsr.ts @@ -150,7 +150,7 @@ class DSRPlugin implements UIRouterPlugin { if (hasParamsConfig) { const currentDSRS: RecordedDSR[] = this.dataStore.get(_state); - const predicate = this.paramsEqual(transTo.$$state(), triggerParams, undefined, true); + const predicate = this.paramsEqual(transTo.$$state(), triggerParams, this.getConfig(state).params, true); const updatedDSRS = currentDSRS.filter(predicate).concat(recordedDSR); this.dataStore.set(_state, updatedDSRS); } else { From c817741f06eacde93d364ee2a8c70a1dee732e29 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Thu, 26 Dec 2019 12:43:05 -0800 Subject: [PATCH 2/2] test(params): Add a test for PR #165 --- test/deepStateRedirectSpec.ts | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/test/deepStateRedirectSpec.ts b/test/deepStateRedirectSpec.ts index 1f978b44..2ed2af1f 100644 --- a/test/deepStateRedirectSpec.ts +++ b/test/deepStateRedirectSpec.ts @@ -1,13 +1,6 @@ -import { getTestGoFn, addCallbacks, resetTransitionLog, pathFrom } from './util'; -import { - UIRouter, - StateService, - StateDeclaration, - servicesPlugin, - memoryLocationPlugin, - StateParams, -} from '@uirouter/core'; +import { memoryLocationPlugin, servicesPlugin, StateDeclaration, StateService, UIRouter } from '@uirouter/core'; import { DSRPlugin } from '../src/dsr'; +import { addCallbacks, getTestGoFn, pathFrom, resetTransitionLog } from './util'; const equalityTester = (first, second) => Object.keys(second).reduce((acc, key) => first[key] == second[key] && acc, true); @@ -211,6 +204,30 @@ describe('deepStateRedirect', function() { done(); }); + // Test for PR #165 + it('should consider only the params from the dsr configuration', async function(done) { + router.stateRegistry.register({ + name: 'rootState1', + url: '/rootstate1/:rootstate1param', + deepStateRedirect: { + params: ['rootstate1param'], + }, + }); + router.stateRegistry.register({ name: 'rootState2', url: '/rootstate2/:rootstate2param' }); + router.stateRegistry.register({ name: 'rootState1.sub1', url: '/sub1' }); + router.stateRegistry.register({ name: 'rootState1.sub2', url: '/sub2/:sub2param' }); + + await $state.go('rootState1.sub1', { rootstate1param: 'rootstate1param' }); + await $state.go('rootState1.sub2', { rootstate1param: 'rootstate1param', sub2param: 'sub2param' }); + await $state.go('rootState2', { rootstate2param: 'rootstate2param' }); + await $state.go('rootState1', { rootstate1param: 'rootstate1param' }); + + const targetState = $deepStateRedirect.getRedirect('rootState1', { rootstate1param: 'rootstate1param' }); + expect(targetState.state().name).toBe('rootState1.sub2'); + + done(); + }); + it('should not redirect if a param is resetted', async function(done) { await $state.go('p3', { param1: 'foo' }); await $state.go('.child');