2019-10-21 06:52:42 +00:00
|
|
|
import './index';
|
2019-12-12 11:23:31 +00:00
|
|
|
import watcher from 'core/mocks/watcher';
|
2019-10-21 06:52:42 +00:00
|
|
|
|
|
|
|
describe('Component vnWorkerPhones', () => {
|
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('worker'));
|
2019-10-21 06:52:42 +00:00
|
|
|
|
|
|
|
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: () => {}};
|
2019-10-21 06:52:42 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2019-10-21 06:52:42 +00:00
|
|
|
});
|