diff options
Diffstat (limited to 'test/ng/routeSpec.js')
| -rw-r--r-- | test/ng/routeSpec.js | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js index d43dcfba..1f714f62 100644 --- a/test/ng/routeSpec.js +++ b/test/ng/routeSpec.js @@ -117,6 +117,72 @@ describe('$route', function() {      });    }); + +  it('should route and fire change event correctly whenever the case insensitive flag is utilized', function() { +    var log = '', +        lastRoute, +        nextRoute; + +    module(function($routeProvider) { +      $routeProvider.when('/Book1/:book/Chapter/:chapter/*highlight/edit', +          {controller: noop, templateUrl: 'Chapter.html', caseInsensitiveMatch: true}); +      $routeProvider.when('/Book2/:book/*highlight/Chapter/:chapter', +          {controller: noop, templateUrl: 'Chapter.html'}); +      $routeProvider.when('/Blank', {}); +    }); +    inject(function($route, $location, $rootScope) { +      $rootScope.$on('$routeChangeStart', function(event, next, current) { +        log += 'before();'; +        expect(current).toBe($route.current); +        lastRoute = current; +        nextRoute = next; +      }); +      $rootScope.$on('$routeChangeSuccess', function(event, current, last) { +        log += 'after();'; +        expect(current).toBe($route.current); +        expect(lastRoute).toBe(last); +        expect(nextRoute).toBe(current); +      }); + +      $location.path('/Book1/Moby/Chapter/Intro/one/edit').search('p=123'); +      $rootScope.$digest(); +      $httpBackend.flush(); +      expect(log).toEqual('before();after();'); +      expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', highlight:'one', p:'123'}); + +      log = ''; +      $location.path('/BOOK1/Moby/CHAPTER/Intro/one/EDIT').search('p=123'); +      $rootScope.$digest(); +      expect(log).toEqual('before();after();'); +      expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', highlight:'one', p:'123'}); + +      log = ''; +      $location.path('/Blank').search('ignore'); +      $rootScope.$digest(); +      expect(log).toEqual('before();after();'); +      expect($route.current.params).toEqual({ignore:true}); + +      log = ''; +      $location.path('/BLANK'); +      $rootScope.$digest(); +      expect(log).toEqual('before();after();'); +      expect($route.current).toEqual(null); + +      log = ''; +      $location.path('/Book2/Moby/one/two/Chapter/Intro').search('p=123'); +      $rootScope.$digest(); +      expect(log).toEqual('before();after();'); +      expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', highlight:'one/two', p:'123'}); + +      log = ''; +      $location.path('/BOOK2/Moby/one/two/CHAPTER/Intro').search('p=123'); +      $rootScope.$digest(); +      expect(log).toEqual('before();after();'); +      expect($route.current).toEqual(null); +    }); +  }); + +    it('should not change route when location is canceled', function() {      module(function($routeProvider) {        $routeProvider.when('/somePath', {template: 'some path'});  | 
