Advertisement
Guest User

Untitled

a guest
Sep 9th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /* jasmine specs for services go here */
  4.  
  5.  
  6. describe('directives', function() {
  7. var scope, elem, $httpBackend, Auth;
  8.  
  9. beforeEach(
  10. module('IonicClean')
  11. );
  12.  
  13. beforeEach(inject(function($injector) {
  14. $httpBackend = $injector.get('$httpBackend');
  15. Auth = $injector.get('Auth');
  16. }));
  17.  
  18. // On module load there will always be a stateChange event to the login state
  19. beforeEach(function() {
  20. $httpBackend.expectGET(/.*/).respond();
  21. $httpBackend.flush();
  22. });
  23.  
  24. afterEach(function() {
  25. $httpBackend.verifyNoOutstandingExpectation();
  26. $httpBackend.verifyNoOutstandingRequest();
  27. });
  28.  
  29. //{{{ accessLevel
  30. describe('accessLevel', function() {
  31.  
  32. it('when user is public and access is public - the menu must be visible',inject(function($compile, $rootScope){
  33.  
  34.  
  35. scope = $rootScope.$new();
  36. scope.accessLevels = routingConfig.accessLevels;
  37.  
  38. var elem = $compile("<li data-access-level='accessLevels.anon'>some text here</li>")(scope);
  39.  
  40. //fire watch
  41. scope.$apply();
  42.  
  43. expect(elem.css('display')).to.equal('');
  44. }));
  45.  
  46.  
  47. it('when user is public and access is user - the menu must be hidden',inject(function($compile, $rootScope){
  48.  
  49. scope = $rootScope.$new();
  50. scope.accessLevels = routingConfig.accessLevels;
  51.  
  52. var elem = $compile("<li data-access-level='accessLevels.user'>some text here</li>")(scope);
  53.  
  54. //fire watch
  55. scope.$apply();
  56.  
  57. expect(elem.css('display')).to.equal('none');
  58. }))
  59. });
  60. //}}}
  61.  
  62. /*
  63. describe('activeNav', function() {
  64.  
  65. var compile, $rootScope, $state, state = 'myState';
  66.  
  67. beforeEach(function() {
  68. inject(function($location, $compile, _$rootScope_, _$state_, _$injector_, $templateCache, $httpBackend) {
  69. $rootScope = _$rootScope_;
  70. $state = _$state_;
  71. location = $location
  72. compile = $compile;
  73.  
  74. // We need add the template entry into the templateCache if we ever
  75. // specify a templateUrl
  76. $templateCache.put('template.html', '');
  77. //$httpBackend.expectGET('register.html').respond();
  78. })
  79. });
  80.  
  81. // for below 2 tests see: http://stackoverflow.com/a/21078955/3905020
  82. it('ui-router should respond to URL', function() {
  83. expect($state.href(state)).to.equal('#/state');
  84. });
  85.  
  86. it('ui-router should switch state', function() {
  87. $state.go(state);
  88. $rootScope.$digest();
  89. expect($state.current.name).to.equal(state);
  90. });
  91.  
  92. it('when location is same as "href" of link - the link must be decorated with "active" class',function(){
  93. $state.go(state);
  94.  
  95. var elem = compile("<li ui-sref-active='active'><a ui-sref='myState'>Register</a></li>")($rootScope);
  96.  
  97. //fire watch
  98. $rootScope.$digest();
  99.  
  100. expect(elem.hasClass('active')).to.be.true;
  101. });
  102.  
  103.  
  104. it.only('when location is different from "href" of link - the "active" class must be removed',function(){
  105. //$state.go(state);
  106. location.path('register');
  107.  
  108. //initially decorated with 'active'
  109. var elem = compile("<li data-active-nav class='active'><a ui-sref='anon.login'>somelink</a></li>")($rootScope);
  110.  
  111. //fire watch
  112. $rootScope.$apply();
  113. console.log(elem);
  114. expect(elem.hasClass('active')).to.equal(false);
  115. });
  116. });
  117. */
  118.  
  119. describe('activeNav', function() {
  120. var location, compile;
  121.  
  122.  
  123. beforeEach(inject(function($compile, $rootScope, $location) {
  124. scope = $rootScope.$new();
  125. location = $location;
  126. location.html5Mode(true); <<----- TypeError: 'undefined' is not a function (evaluating 'location.html5Mode(true)')ERROR:
  127. compile = $compile;
  128. }));
  129.  
  130. it('when location is same as "href" of link - the link must be decorated with "active" class',function(){
  131. location.path('register');
  132. $httpBackend.expectGET('register.html').respond();
  133. $httpBackend.flush();
  134.  
  135. var elem = compile("<li data-active-nav ><a href='http://server/register'>Register</a></li>")(scope);
  136.  
  137. //fire watch
  138. scope.$apply();
  139. expect(elem.hasClass('active')).to.equal(true);
  140. });
  141.  
  142. it('when location is different from "href" of link - the "active" class must be removed',function(){
  143. location.path('register');
  144. $httpBackend.expectGET('register').respond();
  145. $httpBackend.flush();
  146.  
  147. //initially decorated with 'active'
  148. var elem = compile("<li data-active-nav class='active'><a href='http://server/login'>somelink</a></li>")(scope);
  149.  
  150. //fire watch
  151. scope.$apply();
  152. expect(elem.hasClass('active')).to.equal(false);
  153. })
  154. })
  155.  
  156.  
  157. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement