Skip to content

Commit

Permalink
[Core] Support ui.router 1.x $transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygopinath committed Aug 23, 2017
1 parent bbc267d commit f60f296
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/ngMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
useTitleSuffix: false
};

function Meta($rootScope) {
function Meta($rootScope, $injector) {

/**
* @ngdoc method
Expand Down Expand Up @@ -191,6 +191,12 @@
$rootScope.ngMeta = {};
$rootScope.$on('$routeChangeSuccess', update);
$rootScope.$on('$stateChangeSuccess', update);
if ($injector.has('$transitions')) {
var $transitions = $injector.get('$transitions');
$transitions.onSuccess({}, function(transition) {
update(null, transition.$to());
});
}
};

return {
Expand Down Expand Up @@ -306,8 +312,8 @@
};


this.$get = function($rootScope) {
return new Meta($rootScope);
this.$get = function($rootScope, $injector) {
return new Meta($rootScope, $injector);
};
});
}));
35 changes: 32 additions & 3 deletions test/ngMeta.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ describe('Service: ngMeta', function() {

'use strict';

var ngMeta, $rootScope;
var ngMeta, $rootScope, $injector;

// instantiate service
var injectDependencies = function() {
inject(function(_ngMeta_, _$rootScope_) {
inject(function(_ngMeta_, _$rootScope_, _$injector_) {
ngMeta = _ngMeta_;
$rootScope = _$rootScope_;
$injector = _$injector_;
});
};

Expand All @@ -68,12 +69,40 @@ describe('Service: ngMeta', function() {
expect($rootScope.$on).toHaveBeenCalledWith('$routeChangeSuccess', jasmine.any(Function));
});

//ui-router support
//ui-router 0.x support
it('should set up a broadcast listener for $stateChangeSuccess', function() {
spyOn($rootScope, '$on');
ngMeta.init();
expect($rootScope.$on).toHaveBeenCalledWith('$stateChangeSuccess', jasmine.any(Function));
});

//ui-router 1.x support
describe('ui-router 1.x support', function() {
var UI_ROUTER_TRANSITION_SERVICE = '$transitions';

it('should check for the availability of ui-router 1.x\'s $transitions service', function() {
var requestedServiceName;
spyOn($injector, 'has').and.callFake(function(serviceName) {
requestedServiceName = serviceName;
});

ngMeta.init();

expect(requestedServiceName).toEqual(UI_ROUTER_TRANSITION_SERVICE);
});

it('should set up a broadcast listener for $transitions.onSuccess (when $transitions is available)', function() {
var mockTransitionService = {
onSuccess: jasmine.createSpy()
};
spyOn($injector, 'has').and.returnValue(true);
spyOn($injector, 'get').and.returnValue(mockTransitionService);

ngMeta.init();

expect(mockTransitionService.onSuccess).toHaveBeenCalled();
});
});
});

describe('Title: setTitle()', function() {
Expand Down

0 comments on commit f60f296

Please sign in to comment.