salix/modules/worker/front/phones/index.spec.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

import './index';
2019-12-12 11:23:31 +00:00
import watcher from 'core/mocks/watcher';
describe('Component vnWorkerPhones', () => {
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
let $scope = $rootScope.$new();
controller = $componentController('vnWorkerPhones', $scope);
2019-12-12 11:23:31 +00:00
controller.$scope.watcher = watcher;
controller.$scope.model = {
link: 1,
save: () => {}
};
controller.card = {reload: () => {}};
}));
describe('setLink()', () => {
it('set the link in the model and refreshes it', () => {
spyOn(controller.$scope, '$applyAsync');
let value = {userFk: 106};
controller.setLink(value);
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
});
});
2019-12-12 11:23:31 +00:00
describe('onSubmit()', () => {
it('should call watcher functions, reload the card and save the model', done => {
spyOn(controller.$scope.watcher, 'check');
spyOn(controller.$scope.model, 'save').and.returnValue(Promise.resolve());
spyOn(controller.$scope.watcher, 'updateOriginalData');
spyOn(controller.$scope.watcher, 'notifySaved');
spyOn(controller.card, 'reload');
controller.onSubmit();
controller.onSubmit().then(() => {
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
expect(controller.$scope.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
done();
}).catch(done.fail);
});
});
});