mirror of
https://github.com/Febbweiss/CloudBudget-AngularJS.git
synced 2026-03-04 22:35:38 +00:00
Fix: testing account switch
This commit is contained in:
@@ -5,19 +5,17 @@
|
|||||||
.module('cloudbudget')
|
.module('cloudbudget')
|
||||||
.controller('GlobalController', GlobalController);
|
.controller('GlobalController', GlobalController);
|
||||||
|
|
||||||
GlobalController.$inject = ['$scope', '$rootScope', '$location'];
|
GlobalController.$inject = ['$location', '$rootScope'];
|
||||||
|
|
||||||
function GlobalController($scope, $rootScope, $location) {
|
function GlobalController($location, $rootScope) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
vm.change_account = change_account;
|
vm.change_account = change_account;
|
||||||
vm.current_account = undefined;
|
vm.current_account = $rootScope.current_account;;
|
||||||
|
|
||||||
$scope.$watch(function() {
|
$rootScope.$watch('current_account', function() {
|
||||||
return $rootScope.current_account;
|
|
||||||
}, function() {
|
|
||||||
vm.current_account = $rootScope.current_account;
|
vm.current_account = $rootScope.current_account;
|
||||||
}, true);
|
});
|
||||||
|
|
||||||
function change_account() {
|
function change_account() {
|
||||||
$location.path('/account/' + vm.current_account);
|
$location.path('/account/' + vm.current_account);
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ describe('GlobalController', function() {
|
|||||||
beforeEach(inject(function ( _$rootScope_, $controller, _$location_) {
|
beforeEach(inject(function ( _$rootScope_, $controller, _$location_) {
|
||||||
$location = _$location_;
|
$location = _$location_;
|
||||||
$rootScope = _$rootScope_;
|
$rootScope = _$rootScope_;
|
||||||
|
$rootScope.globals = {
|
||||||
|
user: true
|
||||||
|
};
|
||||||
$scope = _$rootScope_.$new();
|
$scope = _$rootScope_.$new();
|
||||||
|
|
||||||
createController = function() {
|
createController = function() {
|
||||||
@@ -39,5 +42,16 @@ describe('GlobalController', function() {
|
|||||||
globalController.change_account();
|
globalController.change_account();
|
||||||
$location.path().should.be.equal('/account/560a84058812ad8d0ff200ee')
|
$location.path().should.be.equal('/account/560a84058812ad8d0ff200ee')
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should change successfully', inject(function($location, $rootScope) {
|
||||||
|
var globalController = createController();
|
||||||
|
globalController.current_account = '560a84058812ad8d0ff200ee';
|
||||||
|
globalController.change_account();
|
||||||
|
$rootScope.current_account = '560a7ad08812ad8d0ff20068';
|
||||||
|
$rootScope.$digest();
|
||||||
|
globalController.change_account();
|
||||||
|
$rootScope.$digest();
|
||||||
|
$location.path().should.be.equal('/account/560a7ad08812ad8d0ff20068')
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user