Billing data copyData and submit unit tests plus small refactor at billing-data.js

This commit is contained in:
Carlos 2017-08-30 08:38:41 +02:00
parent f3b4e33152
commit 5e8f95dd65
2 changed files with 20 additions and 8 deletions

View File

@ -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'),

View File

@ -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();
});
});
});
});