Billing data copyData and submit unit tests plus small refactor at billing-data.js
This commit is contained in:
parent
f3b4e33152
commit
5e8f95dd65
|
@ -1,10 +1,9 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($scope, $http, $timeout, vnApp, $translate) {
|
constructor($scope, $http, vnApp, $translate) {
|
||||||
this.$ = $scope;
|
this.$ = $scope;
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
this.timeout = $timeout;
|
|
||||||
this.vnApp = vnApp;
|
this.vnApp = vnApp;
|
||||||
this.translate = $translate;
|
this.translate = $translate;
|
||||||
this.billData = {};
|
this.billData = {};
|
||||||
|
@ -24,7 +23,7 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
submit() {
|
submit() {
|
||||||
this.$.watcher.submit().then(
|
return this.$.watcher.submit().then(
|
||||||
() => this.checkPaymentChanges());
|
() => this.checkPaymentChanges());
|
||||||
}
|
}
|
||||||
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', {
|
ngModule.component('vnClientBillingData', {
|
||||||
template: require('./billing-data.html'),
|
template: require('./billing-data.html'),
|
||||||
|
|
|
@ -3,17 +3,17 @@ import './billing-data.js';
|
||||||
describe('Component vnClientBillingData', () => {
|
describe('Component vnClientBillingData', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $scope;
|
let $scope;
|
||||||
let vnApp;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
angular.mock.module('client');
|
angular.mock.module('client');
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(function(_$componentController_, $rootScope, _vnApp_) {
|
beforeEach(angular.mock.inject(function(_$componentController_, $rootScope) {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
vnApp = _vnApp_;
|
// try to instanciate the actual watcher instead of submit spy usage.
|
||||||
spyOn(vnApp, 'showError');
|
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
|
||||||
|
$scope.watcher = {submit};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('copyData()', () => {
|
describe('copyData()', () => {
|
||||||
|
@ -32,4 +32,17 @@ describe('Component vnClientBillingData', () => {
|
||||||
expect(controller.billData).toEqual(controller.client);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue