diff --git a/modules/worker/front/phones/index.js b/modules/worker/front/phones/index.js index 3810832d9..91d69ac16 100644 --- a/modules/worker/front/phones/index.js +++ b/modules/worker/front/phones/index.js @@ -24,7 +24,7 @@ class Controller { onSubmit() { this.$scope.watcher.check(); - this.$scope.model.save().then(() => { + return this.$scope.model.save().then(() => { this.$scope.watcher.updateOriginalData(); this.$scope.watcher.notifySaved(); this.card.reload(); diff --git a/modules/worker/front/phones/index.spec.js b/modules/worker/front/phones/index.spec.js index e67e4af89..e3f6f9bf5 100644 --- a/modules/worker/front/phones/index.spec.js +++ b/modules/worker/front/phones/index.spec.js @@ -1,4 +1,5 @@ import './index'; +import watcher from 'core/mocks/watcher'; describe('Component vnWorkerPhones', () => { let controller; @@ -8,8 +9,12 @@ describe('Component vnWorkerPhones', () => { beforeEach(angular.mock.inject(($componentController, $rootScope) => { let $scope = $rootScope.$new(); controller = $componentController('vnWorkerPhones', $scope); - controller.$scope.model = {link: 1}; - controller.$scope.$applyAsync = () => {}; + controller.$scope.watcher = watcher; + controller.$scope.model = { + link: 1, + save: () => {} + }; + controller.card = {reload: () => {}}; })); describe('setLink()', () => { @@ -21,4 +26,22 @@ describe('Component vnWorkerPhones', () => { 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); + }); + }); });