salix/client/core/src/watcher/watcher.spec.js

70 lines
2.5 KiB
JavaScript
Raw Normal View History

import './watcher.js';
describe('Component vnWatcher', () => {
let $componentController;
let $scope;
let $element;
let $state;
let $transitions;
let $httpBackend;
let vnApp;
let $translate;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$transitions_, _$httpBackend_, _vnApp_, _$translate_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
$state = _$state_;
vnApp = _vnApp_;
$transitions = _$transitions_;
$httpBackend = _$httpBackend_;
$translate = _$translate_;
}));
describe('$onInit() ', () => {
it(`should call fetchData() if controllers get and url properties are defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.get = () => {};
controller.url = 'test.com';
spyOn(controller, 'fetchData');
controller.$onInit();
expect(controller.fetchData).toHaveBeenCalledWith();
});
it(`should throw an error if $onInit is called without url defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.get = () => {};
expect(function() {
controller.$onInit();
}).toThrow(new Error('Error: Parameter url ommitted'));
});
});
describe('$onChanges() ', () => {
it(`should call updateOriginalData() if controllers data is defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.data = [];
spyOn(controller, 'updateOriginalData');
controller.$onChanges();
expect(controller.updateOriginalData).toHaveBeenCalledWith();
});
});
describe('$onDestroy() ', () => {
it(`should allways call deregisterCallback()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'deregisterCallback');
controller.$onDestroy();
expect(controller.deregisterCallback).toHaveBeenCalledWith();
});
});
});