Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- /* jasmine specs for services go here */
- describe('directives', function() {
- var scope, elem, $httpBackend, Auth;
- beforeEach(
- module('IonicClean')
- );
- beforeEach(inject(function($injector) {
- $httpBackend = $injector.get('$httpBackend');
- Auth = $injector.get('Auth');
- }));
- // On module load there will always be a stateChange event to the login state
- beforeEach(function() {
- $httpBackend.expectGET(/.*/).respond();
- $httpBackend.flush();
- });
- afterEach(function() {
- $httpBackend.verifyNoOutstandingExpectation();
- $httpBackend.verifyNoOutstandingRequest();
- });
- //{{{ accessLevel
- describe('accessLevel', function() {
- it('when user is public and access is public - the menu must be visible',inject(function($compile, $rootScope){
- scope = $rootScope.$new();
- scope.accessLevels = routingConfig.accessLevels;
- var elem = $compile("<li data-access-level='accessLevels.anon'>some text here</li>")(scope);
- //fire watch
- scope.$apply();
- expect(elem.css('display')).to.equal('');
- }));
- it('when user is public and access is user - the menu must be hidden',inject(function($compile, $rootScope){
- scope = $rootScope.$new();
- scope.accessLevels = routingConfig.accessLevels;
- var elem = $compile("<li data-access-level='accessLevels.user'>some text here</li>")(scope);
- //fire watch
- scope.$apply();
- expect(elem.css('display')).to.equal('none');
- }))
- });
- //}}}
- /*
- describe('activeNav', function() {
- var compile, $rootScope, $state, state = 'myState';
- beforeEach(function() {
- inject(function($location, $compile, _$rootScope_, _$state_, _$injector_, $templateCache, $httpBackend) {
- $rootScope = _$rootScope_;
- $state = _$state_;
- location = $location
- compile = $compile;
- // We need add the template entry into the templateCache if we ever
- // specify a templateUrl
- $templateCache.put('template.html', '');
- //$httpBackend.expectGET('register.html').respond();
- })
- });
- // for below 2 tests see: http://stackoverflow.com/a/21078955/3905020
- it('ui-router should respond to URL', function() {
- expect($state.href(state)).to.equal('#/state');
- });
- it('ui-router should switch state', function() {
- $state.go(state);
- $rootScope.$digest();
- expect($state.current.name).to.equal(state);
- });
- it('when location is same as "href" of link - the link must be decorated with "active" class',function(){
- $state.go(state);
- var elem = compile("<li ui-sref-active='active'><a ui-sref='myState'>Register</a></li>")($rootScope);
- //fire watch
- $rootScope.$digest();
- expect(elem.hasClass('active')).to.be.true;
- });
- it.only('when location is different from "href" of link - the "active" class must be removed',function(){
- //$state.go(state);
- location.path('register');
- //initially decorated with 'active'
- var elem = compile("<li data-active-nav class='active'><a ui-sref='anon.login'>somelink</a></li>")($rootScope);
- //fire watch
- $rootScope.$apply();
- console.log(elem);
- expect(elem.hasClass('active')).to.equal(false);
- });
- });
- */
- describe('activeNav', function() {
- var location, compile;
- beforeEach(inject(function($compile, $rootScope, $location) {
- scope = $rootScope.$new();
- location = $location;
- location.html5Mode(true); <<----- TypeError: 'undefined' is not a function (evaluating 'location.html5Mode(true)')ERROR:
- compile = $compile;
- }));
- it('when location is same as "href" of link - the link must be decorated with "active" class',function(){
- location.path('register');
- $httpBackend.expectGET('register.html').respond();
- $httpBackend.flush();
- var elem = compile("<li data-active-nav ><a href='http://server/register'>Register</a></li>")(scope);
- //fire watch
- scope.$apply();
- expect(elem.hasClass('active')).to.equal(true);
- });
- it('when location is different from "href" of link - the "active" class must be removed',function(){
- location.path('register');
- $httpBackend.expectGET('register').respond();
- $httpBackend.flush();
- //initially decorated with 'active'
- var elem = compile("<li data-active-nav class='active'><a href='http://server/login'>somelink</a></li>")(scope);
- //fire watch
- scope.$apply();
- expect(elem.hasClass('active')).to.equal(false);
- })
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement