it('should send a new item to the server', function(done) {
      var ctx = this;
      ctx.item = { id: 4, name: 'ITEM4' };
      angular.mock.inject(function($rootScope, $httpBackend, itemStorage) {
        $httpBackend.expectPOST('/api/items').respond(201, ctx.item);

        ctx.domain.Item.load.returns(ctx.item);

        var promise = itemStorage.create(ctx.item);

        $httpBackend.flush();
        expect(ctx.domain.Item.load).to.have.been.called;
        expect(promise).notify(done);

        $rootScope.$digest();
      });
    });
Example #2
0
describe('angular-vdom', function () {
  var $compile
  var $rootScope

  beforeEach(angular.mock.module(exampleApp))

  beforeEach(inject(function (_$compile_, _$rootScope_) {
    $compile = _$compile_
    $rootScope = _$rootScope_
  }))

  it('Replaces the element with the appropriate content', function () {
    var element = $compile("<div ng-init='count = 0'><counter count='count'></counter></div>")($rootScope)
    $rootScope.$digest()
    expect(element.html()).to.equal('<counter count="count" class="ng-isolate-scope"><div>virtual-dom: 0</div></counter>')
  })
})
Example #3
0
describe('Browser: OpenExternal', function() {

  beforeEach(angular.mock.module('Etcher.Utils.OpenExternal'));

  describe('openExternal', function() {

    let $compile;
    let $rootScope;

    beforeEach(angular.mock.inject(function(_$compile_, _$rootScope_) {
      $compile = _$compile_;
      $rootScope = _$rootScope_;
    }));

    it('should set the element cursor to pointer', function() {
      const element = $compile('<span open-external="https://resin.io">Resin.io</span>')($rootScope);
      $rootScope.$digest();
      m.chai.expect(element.css('cursor')).to.equal('pointer');
    });

    describe('given non linux', function() {

      beforeEach(function() {
        this.osPlatformStub = m.sinon.stub(os, 'platform');
        this.osPlatformStub.returns('darwin');
      });

      afterEach(function() {
        this.osPlatformStub.restore();
      });

      it('should call Electron shell.openExternal with the attribute value', function() {
        const shellExternalStub = m.sinon.stub(shell, 'openExternal');
        const element = $compile('<span open-external="https://resin.io">Resin.io</span>')($rootScope);
        element.triggerHandler('click');
        $rootScope.$digest();
        m.chai.expect(shellExternalStub).to.have.been.calledWith('https://resin.io');
        shellExternalStub.restore();
      });

    });

  });

});
        describe( 'redirectGiftStep1', () => {
          beforeEach( angular.mock.module( module.name ) );
          let $ctrl;

          beforeEach( inject( ( $componentController ) => {
            $ctrl = $componentController( module.name, {}, {
              onSelectGift: jasmine.createSpy( 'onSelectGift' )
            } );
          } ) );

          it( 'is defined', () => {
            expect( $ctrl ).toBeDefined();
            expect( $ctrl.find ).toEqual( jasmine.any( Function ) );
          } );

          describe( 'selectGift()', () => {
            beforeEach( () => {
              $ctrl.gifts = [{gift: 1}, {gift: 2}, {gift: 3}, {gift: 4}, {gift: 5}];
            } );

            it( 'filters only selected gifts', () => {
              $ctrl.gifts[0]._selectedGift = true;
              $ctrl.gifts[2]._selectedGift = false;
              $ctrl.selectGift();
              expect( $ctrl.onSelectGift ).toHaveBeenCalledWith( {
                gift: {gift: 1, _selectedGift: true}
              } );
            } );
          } );

          describe( 'giftSelected( gift )', () => {
            beforeEach( () => {
              $ctrl.gifts = [{gift: 1}, {gift: 2}, {gift: 3}, {gift: 4}, {gift: 5}];
            } );

            it( 'de-selects previously selected gift', () => {
              $ctrl.gifts[0]._selectedGift = true;
              // gift-list-item selects the gift before calling giftSelected
              $ctrl.gifts[2]._selectedGift = true;
              $ctrl.giftSelected( $ctrl.gifts[2] );
              expect( $ctrl.gifts[2]._selectedGift ).toEqual( true );
              expect( $ctrl.gifts[0]._selectedGift ).toEqual( false );
            } );
          } );
        } );
describe('dynamicDirectiveTemplate directive', function() {

  beforeEach(angular.mock.module('mwl.calendar'));

  var scope, elm, calendarConfig, $templateCache;
  beforeEach(inject(function($rootScope, $compile, _$templateCache_, _calendarConfig_) {
    $templateCache = _$templateCache_;
    calendarConfig = _calendarConfig_;
    scope = $rootScope.$new();
    calendarConfig.templates = {
      foo: 'foo.html'
    };
    scope.baz = 'baz';
    $templateCache.put('foo.html', 'foo {{ baz }}');
    elm = $compile('<div mwl-dynamic-directive-template name="foo" overrides="overrides"></div>')(scope);
    scope.$apply();
  }));

  afterEach(function() {
    elm.remove();
    scope.$destroy();
  });

  it('should fallback to the default template if no custom templates are set', function() {
    expect(elm.text()).to.equal('foo baz');
  });

  it('should fallback to the default template if the custom template name doesnt exist in the cache', function() {
    scope.overrides = {
      foo: 'bam.html'
    };
    scope.$apply();
    expect(elm.text()).to.equal('foo baz');
  });

  it('should use the custom template', function() {
    $templateCache.put('bar.html', 'bar {{ baz }}');
    scope.overrides = {
      foo: 'bar.html'
    };
    scope.$apply();
    expect(elm.text()).to.equal('bar baz');
  });

});
Example #6
0
  beforeEach(function () {
    fakeBridge = { call: sinon.stub() };
    var fakeServiceUrl = sinon.stub().returns('someUrl');
    var fakeSettings = {
      authDomain: 'fakeDomain',
    };
    fakeWindow = { open: sinon.stub() };

    angular.mock.module('app', {
      bridge: fakeBridge,
      serviceUrl: fakeServiceUrl,
      settings: fakeSettings,
      $window: fakeWindow,
    });

    fakeServiceConfig.reset();
    fakeServiceConfig.returns(null);
  });
  beforeEach(function() {
    var ctx = this;
    ctx.domain = {
      Item: ctx.sinon.stub().returnsArg(0),
      Folder: ctx.sinon.stub()
    };

    ctx.domain.Item.load = ctx.sinon.stub().returnsArg(0);

    angular.mock.module('epsonreceipts.storage', {
      domain: ctx.domain,
      offlineStorage: {
        isOffline: function() {
          return false;
        }
      }
    });
  });
Example #8
0
describe('Controller: PreviewCtrl', function() {
  // load the controller's module
  beforeEach(angular.mock.module('SwaggerEditor'));

  var scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function($controller, $rootScope) {
    scope = $rootScope.$new();
    $controller('PreviewCtrl', {
      $scope: scope
    });
  }));

  it('should have a scope', function() {
    expect(Boolean(scope)).to.equal(true);
  });
});
  it('should map routes to controllers', function() {
    angular.module('FirstApp');

    angular.mock.inject(function($route) {

      expect($route.routes['/list'].controller).toBe('ListController');
      expect($route.routes['/list'].templateUrl).
      toEqual('/templates/partials/ListView.html');

      expect($route.routes['/edit-customer/:customerID'].controller).toBe('EditController');
      expect($route.routes['/edit-customer/:customerID'].templateUrl).
      toEqual('/templates/partials/EditView.html');


      // otherwise redirect to
      expect($route.routes[null].redirectTo).toEqual('/');
    });
  });
    describe('when web storage is not supported', function() {

      var sandbox = sinon.sandbox.create();

      beforeEach(function() {
        sandbox.stub(modernizr, 'sessionstorage', false);
      });

      afterEach(function() {
        sandbox.restore();
      });

      it('writes the data to the in memory session', angular.mock.inject(function(session) {
        session.set(key, value);
        expect(session.get(key)).toEqual(value);
      }));

    });
describe('MapcacheCacheController tests', function() {

  var CacheService
    , getCacheExpectation
    , scope
    , ctrl
    , $timeout;

  var sandbox;

  beforeEach(function() {
    sandbox = sinon.sandbox.create();
  });

  afterEach(function() {
    sandbox.restore();
  });

  beforeEach(angular.mock.module('mapcache'));

  beforeEach(inject(function(_CacheService_){
    CacheService = sandbox.mock(_CacheService_);
    getCacheExpectation = CacheService.expects('getCache').yields(mocks.cacheMocks.generatingCache);
  }));

  beforeEach(inject(function($rootScope, $controller, _$timeout_){
    $timeout = _$timeout_;
    scope = $rootScope.$new();
    ctrl = $controller('MapcacheCacheController', {$scope: scope, $routeParams: {
      cacheId: mocks.cacheMocks.generatingCache.id
    }});
  }));

  it('should create the MapcacheCacheController with a generating cache', function() {
    getCacheExpectation.twice();
    should.exist(ctrl);
    scope.formatGenerating.should.be.equal(true);
    scope.hasVectorSources.should.be.equal(false);
    $timeout.flush(5001);
    CacheService.verify();
  });


});
describe('Browser: OSOpenExternal', function() {

  beforeEach(angular.mock.module(
    require('../../../lib/gui/os/open-external/open-external')
  ));

  describe('osOpenExternal', function() {

    let $compile;
    let $rootScope;

    beforeEach(angular.mock.inject(function(_$compile_, _$rootScope_) {
      $compile = _$compile_;
      $rootScope = _$rootScope_;
    }));

    it('should set the element cursor to pointer', function() {
      const element = $compile('<span os-open-external="https://resin.io">Resin.io</span>')($rootScope);
      $rootScope.$digest();
      m.chai.expect(element.css('cursor')).to.equal('pointer');
    });

    it('should call Electron shell.openExternal with the attribute value', function() {
      const shellExternalStub = m.sinon.stub(electron.shell, 'openExternal');
      const element = $compile('<span os-open-external="https://resin.io">Resin.io</span>')($rootScope);
      element.triggerHandler('click');
      $rootScope.$digest();
      m.chai.expect(shellExternalStub).to.have.been.calledWith('https://resin.io');
      shellExternalStub.restore();
    });

    it('should not call Electron shell.openExternal if the attribute value is not defined', function() {
      const shellExternalStub = m.sinon.stub(electron.shell, 'openExternal');
      const element = $compile('<span os-open-external>Resin.io</span>')($rootScope);
      element.triggerHandler('click');
      $rootScope.$digest();
      m.chai.expect(shellExternalStub).to.not.have.been.called;
      shellExternalStub.restore();
    });

  });

});
describe('techs component', () => {
  beforeEach(() => {
    angular
      .module('fountainTechs', ['app/techs/techs.html'])
      .component('fountainTechs', techs);
    angular.mock.module('fountainTechs');
  });

  it('should render 3 elements <fountain-tech>',
    angular.mock.inject(($rootScope, $compile,
      $httpBackend) => {
      $httpBackend.when('GET', 'app/techs/techs.json').respond(techsJson);
      const element = $compile('<fountain-techs></fountain-techs>')($rootScope);
      $httpBackend.flush();
      $rootScope.$digest();
      const techsElement = element.find('fountain-tech');
      expect(techsElement.length).toEqual(3);
    }));
});
Example #14
0
describe('sinon-as-promised angular example', function () {
  var $timeout
  beforeEach(angular.mock.inject(function ($rootScope, $q, _$timeout_) {
    sinonAsPromised($q)
    $timeout = _$timeout_
  }))

  it('can create a stub that resolves', function () {
    var stub = sinon.stub().resolves('value')
    var fulfilled = false
    stub().then(function (value) {
      fulfilled = true
      expect(value).to.equal('value')
    })
    expect(fulfilled).to.equal(false)
    $timeout.flush()
    expect(fulfilled).to.equal(true)
  })
})
  function createController(opts) {
    var locals = {
      $location: {},
      $routeParams: { id: 'test_annotation_id' },
      store: {
        setAppIsSidebar: sinon.stub(),
        setCollapsed: sinon.stub(),
        highlightAnnotations: sinon.stub(),
        subscribe: sinon.stub(),
      },
      api: opts.api,
      rootThread: {thread: sinon.stub()},
      streamer: {
        setConfig: function () {},
        connect: function () {},
      },
      streamFilter: {
        setMatchPolicyIncludeAny: function () {
          return {
            addClause: function () {
              return {
                addClause: function () {},
              };
            },
          };
        },
        getFilter: function () {},
      },
      annotationMapper: {
        loadAnnotations: sinon.spy(),
      },
    };

    var $componentController;
    angular.mock.inject(function (_$componentController_) {
      $componentController = _$componentController_;
    });
    locals.ctrl = $componentController('annotationViewerContent', locals, {
      search: {},
    });
    return locals;
  }
Example #16
0
  describe('functions for team ajax requests', () => {
    var $httpBackend;
    beforeEach(angular.mock.inject(function(_$httpBackend_) {
      $httpBackend = _$httpBackend_;
    }));
    afterEach(() => {
      $httpBackend.verifyNoOutstandingExpectation();
      $httpBackend.verifyNoOutstandingRequest();
    });

    it('should get all teams', () => {
      $httpBackend.expectGET(`${rootRoute}/teams`)
      .respond(200, {teams: [{name: 'test team'}]});
      $httpBackend.expectGET(`${rootRoute}/players`)
      .respond(200, {players: [{name: 'test player', alias: 'test_player'}]});
      apiCtrl.getTeams();
      $httpBackend.flush();
      expect(apiCtrl.teams.length).toBe(1);
      expect(apiCtrl.teams[0].name).toBe('test team');
    });

    it('should create a team', () => {
      apiCtrl.teams = [];
      $httpBackend.expectPOST(`${rootRoute}/teams`)
      .respond(200, {team: {name: 'test team', region: 'test', _id: '456'}});
      apiCtrl.addTeam({name: 'test'});
      $httpBackend.flush();
      expect(apiCtrl.teams.length).toBe(1);
      expect(apiCtrl.teams[0].name).toBe('test team');
      expect(apiCtrl.teams[0]._id).toBe('456');
    });

    it('should delete a team', () => {
      apiCtrl.teams = [{name: 'test team', _id: '456'}];
      $httpBackend.expectDELETE(`${rootRoute}/teams/456`)
      .respond(200, {message:'team deleted'});
      apiCtrl.deleteTeam(apiCtrl.teams[0]);
      $httpBackend.flush();
      expect(apiCtrl.teams.length).toBe(0);
      expect(apiCtrl.teams[0]).toBeUndefined();
    });
  });
Example #17
0
module.exports = function () {

  var campaign;
  beforeEach(angular.mock.inject(function ($injector) {
    var Campaign   = $injector.get('Campaign');
    campaign   = new Campaign();
  }));

  it('can generate a Firebase reference to all pledges for a campaign', function () {
    expect(campaign.pledges.$ref().currentPath)
      .to.equal('Mock://campaigns/' + campaign.id + '/live/pledges');
  });

  it('can generate a Firebase reference to a single pledge', function () {
    var pledge = campaign.pledges.$new();
    expect(pledge.$ref().currentPath)
      .to.equal('Mock://campaigns/' + campaign.id + '/live/pledges/' + pledge.id);
  });

};
Example #18
0
describe('Directive: schemaModel', function() {
  // load the directive's module
  beforeEach(angular.mock.module('SwaggerEditor'));

  var element;
  var scope;

  beforeEach(inject(function($rootScope) {
    scope = $rootScope.$new();
  }));

  it('should render', inject(function($compile) {
    scope.stringSchema = {type: 'string'};
    element = angular.element(
      '<schema-model schema="stringSchema"></schema-model>'
    );
    element = $compile(element)(scope);
    expect(element.text()).to.contain('⇄');
  }));
});
Example #19
0
    beforeEach(() => {
      const url = 'https://geomapfish-demo-2-4.camptocamp.com/mapserv_proxy';
      angular.mock.inject((_$httpBackend_) => {
        $httpBackend = _$httpBackend_;
        $httpBackend.when('POST', url).respond(ngeoTestDataMsGMLOutputFuel);
      });

      const projection = olProj.get('EPSG:21781');
      projection.setExtent([485869.5728, 76443.1884, 837076.5648, 299941.7864]);

      map = new olMap({
        layers: [],
        view: new olView({
          projection: projection,
          resolutions: [200, 100, 50, 20, 10, 5, 2.5, 2, 1, 0.5],
          center: [537635, 152640],
          zoom: 0
        })
      });
    });
    it('should filter the item collection', function() {
      var ctx = this;
      angular.mock.inject(function($rootScope, $httpBackend, itemStorage) {
        ctx.scope = $rootScope.$new();
        $httpBackend.whenGET('/api/items').respond(200, ctx.items);
        $httpBackend.whenGET('/api/folders').respond(200);

        itemStorage.watch(ctx.scope, function(result) {
          ctx.result = result;
        }).setFilter('isItem1', function(item) {
          return item.name === 'ITEM1';
        });

        $httpBackend.flush();
        $rootScope.$digest();

        expect(ctx.result).not.to.deep.equal(ctx.items);
        expect(ctx.result).to.have.deep.members(ctx.items.slice(0, 1));
      });
    });
describe('autocomplete directive', function() {
  global.jQuery = require('jquery');
  var fixtures = require('../fixtures.js');

  var angular = require('angular');
  require('../../src/angular/directive.js');
  require('angular-mocks');

  var scope;

  beforeEach(angular.mock.module('algolia.autocomplete'));

  describe('with scope', function() {
    beforeEach(angular.mock.inject(function($rootScope, $compile) {
      scope = $rootScope.$new();
      scope.q = '';
      scope.getDatasets = function() {
        return [];
      };
    }));

    describe('when initialized', function() {
      var form;

      beforeEach(function() {
        inject(function($compile) {
          form = $compile(fixtures.html.angularTextInput)(scope);
        });
        scope.$digest();
      });

      it('should have a parent', function() {
        expect(form.parent().length).toEqual(1);
      });
    });
  });

  afterAll(function() {
    global.jQuery = undefined;
  });
});
Example #22
0
  describe('CRUD tests', ()=>{
    var $httpBackend;
    beforeEach(angular.mock.inject(function(_$httpBackend_){
      $httpBackend = _$httpBackend_;
    }));
    afterEach(()=>{
      $httpBackend.verifyNoOutstandingExpectation();
      $httpBackend.verifyNoOutstandingRequest();
    })
    it('should get all projects', ()=>{
      $httpBackend.expectGET('http://localhost:3000/projects')
       .respond(200, {projects: [{name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410'}]});
       ProjectController.getProjects();
       $httpBackend.flush();
       console.log(ProjectController.projects);
      //  expect(ProjectController.projects.length).toBeGreaterThan(0);
       expect(ProjectController.projects[0].name).toBe('Hey');
       expect(ProjectController.projects[0].description).toBe('thisistest');
       expect(ProjectController.projects[0].created).toBe('5/2/16');
       expect(ProjectController.projects[0].course).toBe('410');

    });
    it('post a new project', ()=>{
      $httpBackend.expectPOST('http://localhost:3000/projects', {name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410'})
      .respond(200, {name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410'});
      ProjectController.createProject({name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410'});
      $httpBackend.flush();
      console.log(ProjectController.projects);
      expect(ProjectController.projects.length).toBeGreaterThan(0);

    });
    it('should delete a project', ()=>{
      $httpBackend.expectDelete('http://localhost:3000/projects/6')
      .respond(200, {msg: 'project removed'});
      ProjectController.projects.push({name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410', _id: 6});
      ProjectController.removeProject({name: 'Hey', description: 'thisistest', created: '5/2/16', course: '410', _id: 6});
      $httpBackend.flush();
      expect(ProjectController.projects.length).toBe(1);
      expect(ProjectController.projects.every((p)=> p._id !=6)).toBe(true);
    });
  });
Example #23
0
    describe('#submit', function () {

      beforeEach(function () {
        sinon.stub($state, 'go');
      });

      it('submits the pledge and donor in a sequential batch', function () {
        $httpBackend
          .expectPOST(config.valet.api + '/batch', angular.toJson({
            requests: [
              {
                method: 'POST',
                path: '/donors',
                payload: scope.pledge.donor
              },
              {
                method: 'POST',
                path: '/pledges',
                payload: scope.pledge
              }
            ],
            parallel: false
          }))
          .respond(200, [
            scope.pledge,
            scope.pledge.donor
          ]);
        scope.submit();
        $httpBackend.flush();
      });

      it('transitions to the confirmation', angular.mock.inject(function ($q, $timeout) {
        sinon.stub(scope.pledge, '$batch').resolves();
        scope.submit();
        $timeout.flush();
        expect($state.go).to.have.been.calledWithMatch('^.confirmation', {
          id: scope.pledge.id
        });
      }));

    });
Example #24
0
    context('when browser localStorage is *not* accessible', () => {
      let localStorage = null;
      let key = null;

      beforeEach(() => {
        angular.mock.module('h', {
          $window,
        });
      });

      beforeEach(
        angular.mock.inject(_localStorage_ => {
          localStorage = _localStorage_;
          key = 'test.memory.key';
        })
      );

      it('sets/gets Item', () => {
        const value = 'What shall we do with a drunken sailor?';
        localStorage.setItem(key, value);
        const actual = localStorage.getItem(key);
        assert.equal(value, actual);
      });

      it('removes item', () => {
        localStorage.setItem(key, '');
        localStorage.removeItem(key);
        const result = localStorage.getItem(key);
        assert.isNull(result);
      });

      it('sets/gets Object', () => {
        const data = { foo: 'bar' };
        localStorage.setObject(key, data);
        const stringified = localStorage.getItem(key);
        assert.equal(stringified, JSON.stringify(data));

        const actual = localStorage.getObject(key);
        assert.deepEqual(actual, data);
      });
    });
  describe('battle function', function() {
    var $httpBackend;
    var battlectrl;

    beforeEach(angular.mock.inject(function(_$httpBackend_) {
      $httpBackend = _$httpBackend_;
      battlectrl = $controller('BattleController');
    }));

    afterEach(function() {
      $httpBackend.verifyNoOutstandingExpectation();
      $httpBackend.verifyNoOutstandingRequest();
    });

    it('should create a battle', function() {
      $httpBackend.expectGET('http://localhost:3000/api/battle').respond(200, 'test string');
      battlectrl.battle();
      $httpBackend.flush();
      expect(battlectrl.battles.length).not.toBe(0);
    });
  });
  beforeEach(function() {
    const app = angular.module('myApp', []);

    githubUserServiceMock = jasmine.createSpyObj('githubUserServiceMock', ['user', 'repos']);
    app.provider('githubUser', { $get: function () { return githubUserServiceMock; }});
    app.directive('githubApiAvailable', GithubApiAvailable);

    angular.mock.module('myApp');

    inject(function($injector) {
        $compile = $injector.get('$compile');
        $scope = $injector.get('$rootScope');
        $q = $injector.get('$q');

        $compile(
            `<form name="form">
            <input name="user" ng-model="user" github-api-available />
            </form>`
        )($scope);
      });
  });
describe("FlugList", function () {
    var httpBackend;
    var flightSearch;
    beforeEach(angular_1.mock.module("flight-app", function ($provide) {
    }));
    beforeEach(inject(function ($controller, $rootScope, $httpBackend) {
        var $scope = $rootScope.$new();
        flightSearch = $controller("flightSearch", { $scope: $scope });
        httpBackend = $httpBackend;
        $httpBackend
            .expect('GET', 'http://www.angular.at/api/flight?from=Graz&to=Linz')
            .respond([
            { id: 1, from: 'Graz', to: 'Linz', date: '2016-12-24' }
        ]);
    }));
    afterEach(function () {
        httpBackend.verifyNoOutstandingExpectation();
        httpBackend.verifyNoOutstandingRequest();
    });
    it("should load flights", function () {
        // Arrange
        flightSearch.from = 'Graz';
        flightSearch.to = 'Linz';
        var error = false;
        // Act
        flightSearch
            .search()
            .then(function () {
            // Do nothing
        })
            .catch(function () {
            error = true;
        });
        // Antwort durch MockBackend simulieren
        httpBackend.flush();
        // Assert
        expect(error).toBe(false);
        expect(flightSearch.flights.length).toBe(1);
    });
});
describe('ngeo.misc.DecorateLayerLoading test suite', () => {
  /** @type {angular.IScope} */
  let scope;

  beforeEach(angular.mock.inject(($rootScope) => {
    scope = $rootScope.$new();
  }));

  it('should increment layerLoadingCount recursively', () => {
    const imageSource = new olSourceImage({
      projection: undefined, // should be removed in next OL version
    });
    const layer = new olLayerImage({source: imageSource});
    const lg_1 = new olLayerGroup();
    const lg_2 = new olLayerGroup();

    layerLoading(layer, scope);
    layerLoading(lg_1, scope);
    layerLoading(lg_2, scope);

    lg_1.getLayers().insertAt(0, layer);
    lg_2.getLayers().insertAt(0, lg_1);

    expect(layer.get('load_count')).toBe(0);
    expect(lg_1.get('load_count')).toBe(0);
    expect(lg_2.get('load_count')).toBe(0);

    imageSource.dispatchEvent('imageloadstart');

    expect(layer.get('load_count')).toBe(1);
    expect(lg_1.get('load_count')).toBe(1);
    expect(lg_2.get('load_count')).toBe(1);

    imageSource.dispatchEvent('imageloadend');

    expect(layer.get('load_count')).toBe(0);
    expect(lg_1.get('load_count')).toBe(0);
    expect(lg_2.get('load_count')).toBe(0);
  });
});
describe( 'userMatchQuestion', function () {
  beforeEach( angular.mock.module( module.name ) );
  let $ctrl, bindings;

  beforeEach( inject( function ( _$componentController_ ) {
    bindings = {
      onQuestionAnswer: jasmine.createSpy( 'onQuestionAnswer' ),
      questionForm:     {$valid: false},
      question:         {key: 'key'},
      answer:           {answer: 'answer'}
    };
    $ctrl = _$componentController_( module.name, {}, bindings );
  } ) );

  it( 'to be defined', function () {
    expect( $ctrl ).toBeDefined();
    expect( $ctrl.hasError ).toEqual( false );
  } );

  describe( 'selectAnswer()', () => {
    describe( 'invalid form', () => {
      it( 'sets hasError', () => {
        $ctrl.selectAnswer();
        expect( $ctrl.hasError ).toEqual( true );
        expect( $ctrl.onQuestionAnswer ).not.toHaveBeenCalled();
        expect( $ctrl.answer ).toEqual({answer: 'answer'});
      } );
    } );

    describe( 'valid form', () => {
      it( 'submits the answer', () => {
        $ctrl.questionForm.$valid = true;
        expect( $ctrl.answer ).toEqual({answer: 'answer'});
        $ctrl.selectAnswer();
        expect( $ctrl.onQuestionAnswer ).toHaveBeenCalledWith( {key: 'key', answer: 'answer'} );
        expect( $ctrl.answer ).toBeUndefined();
      } );
    } );
  } );
} );
describe('Sidepanel actions service', () => {
	let stateMock;

	beforeEach(angular.mock.module('app.settings.actions', ($provide) => {
		stateMock = { home: { sidePanelDocked: true }};
		$provide.constant('state', stateMock);
	}));

	describe('dispatch', () => {
		beforeEach(inject((StorageService, StateService, SidePanelActionsService) => {
			// given
			const action = {
				"type": "@@sidepanel/TOGGLE",
				"payload": {
					"method": "toggleHomeSidepanel",
					"args": []
				}
			};
			spyOn(StateService, 'toggleHomeSidepanel').and.returnValue();
			spyOn(StorageService, 'setSidePanelDock').and.returnValue();

			// when
			SidePanelActionsService.dispatch(action);
		}));

		it('should toggle sidepanel', inject((StateService) => {
			// then
			expect(StateService.toggleHomeSidepanel).toHaveBeenCalled();
		}));

		it('should save docked state in local storage', inject((StorageService) => {
			// given
			const docked = stateMock.home.sidePanelDocked;

			// then
			expect(StorageService.setSidePanelDock).toHaveBeenCalledWith(docked);
		}));
	});
});