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;
}
@ -32,15 +31,15 @@ class Controller {
let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`;
let data = {
landed: this.ticket.landed,
addressFk: this.ticket.addressFk,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
};
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(
@ -50,12 +49,12 @@ class Controller {
}
isFormInvalid() {
return !this.ticket.clientFk || !this.ticket.addressFk || !this.ticket.agencyModeFk
return !this.ticket.clientFk || !this.ticket.addressFk || !this.ticket.agencyModeFk
|| !this.ticket.companyFk || !this.ticket.shipped || !this.ticket.landed;
}
}
Controller.$inject = ['$scope', '$http', '$element', '$translate', 'vnApp'];
Controller.$inject = ['$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnTicketDataStepOne', {
template: require('./step-one.html'),

View File

@ -21,14 +21,14 @@ 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();
expect(result).toBeFalsy();
});
@ -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();
});
});
});