Refactor step-one unit test

This commit is contained in:
gerard 2018-05-22 08:14:16 +02:00
parent 73104c4465
commit d21b57e536
2 changed files with 22 additions and 23 deletions

View File

@ -1,10 +1,9 @@
import ngModule from '../../module';
class Controller {
constructor($scope, $http, $element, $translate, vnApp) {
constructor($scope, $http, $translate, vnApp) {
this.$scope = $scope;
this.$http = $http;
this.$element = $element;
this.$translate = $translate;
this.vnApp = vnApp;
}
@ -14,7 +13,7 @@ class Controller {
}
onChange() {
if(this.ticket)
if (this.ticket)
this.ticket.addressFk = null;
}
@ -37,10 +36,10 @@ class Controller {
};
return this.$http.post(query, data).then(res => {
if (res.data);
if (res.data)
this.ticket.sale = res.data;
return true
return true;
}, res => {
if (res.data.error.message === 'NO_AGENCY_AVAILABLE')
this.vnApp.showError(
@ -55,7 +54,7 @@ class Controller {
}
}
Controller.$inject = ['$scope', '$http', '$element', '$translate', 'vnApp'];
Controller.$inject = ['$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnTicketDataStepOne', {
template: require('./step-one.html'),

View File

@ -21,12 +21,12 @@ describe('ticket', () => {
describe('isFormInvalid()', () => {
it('should check if all form fields are valid', () => {
controller.ticket = {
clientFk: 1,
addressFk: 121,
agencyModeFk: 1,
companyFk: 442,
shipped: Date.now(),
landed: Date.now()
clientFk: 1,
addressFk: 121,
agencyModeFk: 1,
companyFk: 442,
shipped: Date.now(),
landed: Date.now()
};
let result = controller.isFormInvalid();
@ -44,19 +44,19 @@ describe('ticket', () => {
companyFk: 442,
shipped: Date.now(),
landed: Date.now()
};
};
let data = {
let data = {
addressFk: 121,
agencyModeFk: 1,
landed: Date.now()
};
let response = {error: {message: 'NO_AGENCY_AVAILABLE'}};
};
let response = {error: {message: 'NO_AGENCY_AVAILABLE'}};
$httpBackend.whenPOST(`/ticket/api/sales/1/priceDifference`, data).respond(400, response);
$httpBackend.expectPOST(`/ticket/api/sales/1/priceDifference`, data);
controller.onStepChange();
$httpBackend.flush();
$httpBackend.whenPOST(`/ticket/api/sales/1/priceDifference`, data).respond(400, response);
$httpBackend.expectPOST(`/ticket/api/sales/1/priceDifference`, data);
controller.onStepChange();
$httpBackend.flush();
});
});
});