global.controller.spec.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. describe('GlobalController', function() {
  2. var $location,
  3. $rootScope,
  4. $scope,
  5. createController,
  6. DEFAULT_ACCOUNTS = [
  7. {
  8. "_id": "560a84058812ad8d0ff200ee",
  9. "name": "foo",
  10. "reference": "baz",
  11. "user_id": "55b78934d2a706265ea28e9c"
  12. }, {
  13. "_id": "560a7ad08812ad8d0ff20068",
  14. "name": "bar",
  15. "user_id": "55b78934d2a706265ea28e9c"
  16. }
  17. ];
  18. beforeEach(module('cloudbudget'));
  19. beforeEach(inject(function ( _$rootScope_, $controller, _$location_) {
  20. $location = _$location_;
  21. $rootScope = _$rootScope_;
  22. $rootScope.globals = {
  23. user: true
  24. };
  25. $scope = _$rootScope_.$new();
  26. createController = function() {
  27. return $controller('GlobalController', {
  28. '$scope': $scope,
  29. '$location': $location,
  30. '$rootScope': $rootScope
  31. });
  32. };
  33. }));
  34. it('should init successfully', inject(function($location, $rootScope) {
  35. var globalController = createController();
  36. globalController.current_account = '560a84058812ad8d0ff200ee';
  37. globalController.change_account();
  38. $location.path().should.be.equal('/account/560a84058812ad8d0ff200ee')
  39. }));
  40. it('should change successfully', inject(function($location, $rootScope) {
  41. var globalController = createController();
  42. globalController.current_account = '560a84058812ad8d0ff200ee';
  43. globalController.change_account();
  44. $rootScope.current_account = '560a7ad08812ad8d0ff20068';
  45. $rootScope.$digest();
  46. globalController.change_account();
  47. $rootScope.$digest();
  48. $location.path().should.be.equal('/account/560a7ad08812ad8d0ff20068')
  49. }));
  50. });