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'; import ngModule from '../../module';
class Controller { class Controller {
constructor($scope, $http, $element, $translate, vnApp) { constructor($scope, $http, $translate, vnApp) {
this.$scope = $scope; this.$scope = $scope;
this.$http = $http; this.$http = $http;
this.$element = $element;
this.$translate = $translate; this.$translate = $translate;
this.vnApp = vnApp; this.vnApp = vnApp;
} }
@ -14,7 +13,7 @@ class Controller {
} }
onChange() { onChange() {
if(this.ticket) if (this.ticket)
this.ticket.addressFk = null; this.ticket.addressFk = null;
} }
@ -32,15 +31,15 @@ class Controller {
let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`; let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`;
let data = { let data = {
landed: this.ticket.landed, landed: this.ticket.landed,
addressFk: this.ticket.addressFk, addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk agencyModeFk: this.ticket.agencyModeFk
}; };
return this.$http.post(query, data).then(res => { return this.$http.post(query, data).then(res => {
if (res.data); if (res.data)
this.ticket.sale = res.data; this.ticket.sale = res.data;
return true return true;
}, res => { }, res => {
if (res.data.error.message === 'NO_AGENCY_AVAILABLE') if (res.data.error.message === 'NO_AGENCY_AVAILABLE')
this.vnApp.showError( this.vnApp.showError(
@ -50,12 +49,12 @@ class Controller {
} }
isFormInvalid() { 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; || !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', { ngModule.component('vnTicketDataStepOne', {
template: require('./step-one.html'), template: require('./step-one.html'),

View File

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