diff --git a/client/client/src/billing-data/billing-data.js b/client/client/src/billing-data/billing-data.js index 9a10095c9..0b374fcbd 100644 --- a/client/client/src/billing-data/billing-data.js +++ b/client/client/src/billing-data/billing-data.js @@ -1,10 +1,9 @@ import ngModule from '../module'; export default class Controller { - constructor($scope, $http, $timeout, vnApp, $translate) { + constructor($scope, $http, vnApp, $translate) { this.$ = $scope; this.$http = $http; - this.timeout = $timeout; this.vnApp = vnApp; this.translate = $translate; this.billData = {}; @@ -24,7 +23,7 @@ export default class Controller { } } submit() { - this.$.watcher.submit().then( + return this.$.watcher.submit().then( () => this.checkPaymentChanges()); } checkPaymentChanges() { @@ -48,7 +47,7 @@ export default class Controller { } } } -Controller.$inject = ['$scope', '$http', '$timeout', 'vnApp', '$translate']; +Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; ngModule.component('vnClientBillingData', { template: require('./billing-data.html'), diff --git a/client/client/src/billing-data/billing-data.spec.js b/client/client/src/billing-data/billing-data.spec.js index da2e2f21d..e6984da89 100644 --- a/client/client/src/billing-data/billing-data.spec.js +++ b/client/client/src/billing-data/billing-data.spec.js @@ -3,17 +3,17 @@ import './billing-data.js'; describe('Component vnClientBillingData', () => { let $componentController; let $scope; - let vnApp; beforeEach(() => { angular.mock.module('client'); }); - beforeEach(angular.mock.inject(function(_$componentController_, $rootScope, _vnApp_) { + beforeEach(angular.mock.inject(function(_$componentController_, $rootScope) { $componentController = _$componentController_; $scope = $rootScope.$new(); - vnApp = _vnApp_; - spyOn(vnApp, 'showError'); + // try to instanciate the actual watcher instead of submit spy usage. + let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve()); + $scope.watcher = {submit}; })); describe('copyData()', () => { @@ -32,4 +32,17 @@ describe('Component vnClientBillingData', () => { expect(controller.billData).toEqual(controller.client); }); }); + + describe('submit()', () => { + it(`should call submit() on the watcher then receive a callback`, done => { + let controller = $componentController('vnClientBillingData', {$scope: $scope}); + spyOn(controller, 'checkPaymentChanges'); + controller.submit() + .then(() => { + expect(controller.$.watcher.submit).toHaveBeenCalled(); + expect(controller.checkPaymentChanges).toHaveBeenCalled(); + done(); + }); + }); + }); });