Client side unit tests for spinner

This commit is contained in:
Carlos 2017-10-13 17:35:47 +02:00
parent 82e4fdab68
commit d7668c278d
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
import './spinner.js';
describe('Component vnSpinner', () => {
let $componentController;
let $scope;
let $element;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$element = angular.element('<div><div></div></div>');
}));
describe('enable()', () => {
it(`should call start() based on a boolean value passed as argument`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = true;
expect(controller.start).toHaveBeenCalledWith();
expect(controller.stop).not.toHaveBeenCalledWith();
});
it(`should call stop() based on a boolean value passed as argument`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = false;
expect(controller.start).not.toHaveBeenCalledWith();
expect(controller.stop).toHaveBeenCalledWith();
});
});
describe('start()', () => {
it(`should call start() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
controller.spinner = {MaterialSpinner: {start: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'start');
controller._enable = false;
controller.start();
expect(controller.spinner.MaterialSpinner.start).toHaveBeenCalledWith();
expect(controller._enable).toBeTruthy();
});
});
describe('stop()', () => {
it(`should call stop() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
controller.spinner = {MaterialSpinner: {stop: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'stop');
controller._enable = true;
controller.stop();
expect(controller.spinner.MaterialSpinner.stop).toHaveBeenCalledWith();
expect(controller._enable).toBeFalsy();
});
});
});