import './index'; 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); 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)); }); }); 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); }); }); });