From 71d7469987ee9ca86a41c8c6393ccd5d8913c3d6 Mon Sep 17 00:00:00 2001 From: Phil Brown Date: Mon, 28 Sep 2015 12:02:12 +1000 Subject: [PATCH] feat(isStateFilter): Include optional state params. Allows state params to be passed to the `isState` filter for more accurate matching. --- src/stateFilters.js | 4 ++-- test/stateFiltersSpec.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/stateFilters.js b/src/stateFilters.js index e0a117580..9156e6f42 100644 --- a/src/stateFilters.js +++ b/src/stateFilters.js @@ -9,8 +9,8 @@ */ $IsStateFilter.$inject = ['$state']; function $IsStateFilter($state) { - var isFilter = function (state) { - return $state.is(state); + var isFilter = function (state, params) { + return $state.is(state, params); }; isFilter.$stateful = true; return isFilter; diff --git a/test/stateFiltersSpec.js b/test/stateFiltersSpec.js index 7f2eb9beb..a3aa93f06 100644 --- a/test/stateFiltersSpec.js +++ b/test/stateFiltersSpec.js @@ -3,7 +3,8 @@ describe('isState filter', function() { beforeEach(module(function($stateProvider) { $stateProvider .state('a', { url: '/' }) - .state('a.b', { url: '/b' }); + .state('a.b', { url: '/b' }) + .state('with-param', { url: '/with/:param' }); })); it('should return true if the current state exactly matches the input state', inject(function($parse, $state, $q, $rootScope) { @@ -17,6 +18,18 @@ describe('isState filter', function() { $q.flush(); expect($parse('"a" | isState')($rootScope)).toBe(false); })); + + it('should return true if the current state and param matches the input state', inject(function($parse, $state, $q, $rootScope) { + $state.go('with-param', {param: 'a'}); + $q.flush(); + expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(true); + })); + + it('should return false if the current state and param does not match the input state', inject(function($parse, $state, $q, $rootScope) { + $state.go('with-param', {param: 'b'}); + $q.flush(); + expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(false); + })); }); describe('includedByState filter', function() {