update zone and shipped on #1746
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-10-04 09:28:09 +02:00
parent 02f5ee73da
commit 10d97674dc
3 changed files with 179 additions and 37 deletions

View File

@ -14,6 +14,7 @@
label="Client" label="Client"
show-field="name" show-field="name"
value-field="id" value-field="id"
search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}"
field="$ctrl.clientId" field="$ctrl.clientId"
initial-data="$ctrl.clientId" initial-data="$ctrl.clientId"
order="id"> order="id">
@ -23,7 +24,7 @@
label="Address" label="Address"
show-field="nickname" show-field="nickname"
value-field="id" value-field="id"
field="$ctrl.ticket.addressFk" field="$ctrl.addressId"
order="isActive DESC"> order="isActive DESC">
<tpl-item ng-class="::{notActive: isActive === false}"> <tpl-item ng-class="::{notActive: isActive === false}">
<span class="inactive" translate>{{::isActive ? '' : 'INACTIVE'}}</span> {{::nickname}} <span class="inactive" translate>{{::isActive ? '' : 'INACTIVE'}}</span> {{::nickname}}

View File

@ -26,10 +26,7 @@ class Controller {
} }
get clientId() { get clientId() {
if (this.ticket) return this.ticket && this.ticket.clientFk;
return this.ticket.clientFk;
return null;
} }
set clientId(value) { set clientId(value) {
@ -39,11 +36,24 @@ class Controller {
this.onChangeClient(value); this.onChangeClient(value);
} }
get warehouseId() { get addressId() {
if (this.ticket) return this.ticket && this.ticket.addressFk;
return this.ticket.warehouseFk; }
return null; set addressId(value) {
if (value != this.ticket.addressFk) {
this.ticket.addressFk = value;
this.getShipped({
landed: this.ticket.landed,
addressFk: value,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
});
}
}
get warehouseId() {
return this.ticket && this.ticket.warehouseFk;
} }
set warehouseId(value) { set warehouseId(value) {
@ -60,10 +70,7 @@ class Controller {
get shipped() { get shipped() {
if (this.ticket) return this.ticket && this.ticket.shipped;
return this.ticket.shipped;
return null;
} }
set shipped(value) { set shipped(value) {
@ -77,10 +84,7 @@ class Controller {
} }
get landed() { get landed() {
if (this.ticket) return this.ticket && this.ticket.landed;
return this.ticket.landed;
return null;
} }
set landed(value) { set landed(value) {
@ -94,17 +98,14 @@ class Controller {
} }
get agencyModeId() { get agencyModeId() {
if (this.ticket) return this.ticket && this.ticket.agencyModeFk;
return this.ticket.agencyModeFk;
return null;
} }
set agencyModeId(value) { set agencyModeId(value) {
if (value != this.ticket.agencyModeFk) { if (value != this.ticket.agencyModeFk) {
this.ticket.agencyModeFk = value; this.ticket.agencyModeFk = value;
this.getShipped({ this.getLanded({
landed: this.ticket.landed, shipped: this.ticket.shipped,
addressFk: this.ticket.addressFk, addressFk: this.ticket.addressFk,
agencyModeFk: value, agencyModeFk: value,
warehouseFk: this.ticket.warehouseFk warehouseFk: this.ticket.warehouseFk
@ -113,10 +114,7 @@ class Controller {
} }
get zoneId() { get zoneId() {
if (this.ticket) return this.ticket && this.ticket.zoneFk;
return this.ticket.zoneFk;
return null;
} }
set zoneId(value) { set zoneId(value) {
@ -206,9 +204,10 @@ class Controller {
this.$http.get(query, {params}).then(res => { this.$http.get(query, {params}).then(res => {
if (res.data) { if (res.data) {
this.ticket.zoneFk = res.data.zoneFk; this.ticket.zoneFk = res.data.zoneFk;
this.ticket.landed = res.data.landed;
this.ticket.agencyModeFk = res.data.agencyModeFk; this.ticket.agencyModeFk = res.data.agencyModeFk;
this.ticket.warehouseFk = res.data.warehouseFk; this.ticket.warehouseFk = res.data.warehouseFk;
this.ticket.landed = res.data.landed;
this.ticket.shipped = params.shipped;
} else { } else {
return this.vnApp.showError( return this.vnApp.showError(
this.$translate.instant(`No delivery zone available for this landing date`) this.$translate.instant(`No delivery zone available for this landing date`)
@ -226,9 +225,10 @@ class Controller {
this.$http.get(query, {params}).then(res => { this.$http.get(query, {params}).then(res => {
if (res.data) { if (res.data) {
this.ticket.zoneFk = res.data.zoneFk; this.ticket.zoneFk = res.data.zoneFk;
this.ticket.shipped = res.data.shipped;
this.ticket.agencyModeFk = res.data.agencyModeFk; this.ticket.agencyModeFk = res.data.agencyModeFk;
this.ticket.warehouseFk = res.data.warehouseFk; this.ticket.warehouseFk = res.data.warehouseFk;
this.ticket.landed = params.landed;
this.ticket.shipped = res.data.shipped;
} else { } else {
return this.vnApp.showError( return this.vnApp.showError(
this.$translate.instant(`No delivery zone available for this landing date`) this.$translate.instant(`No delivery zone available for this landing date`)

View File

@ -5,14 +5,16 @@ describe('Ticket', () => {
let $state; let $state;
let controller; let controller;
let $httpBackend; let $httpBackend;
let $httpParamSerializer;
beforeEach(angular.mock.module('ticket', $translateProvider => { beforeEach(angular.mock.module('ticket', $translateProvider => {
$translateProvider.translations('en', {}); $translateProvider.translations('en', {});
})); }));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
$state = _$state_; $state = _$state_;
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnTicketBasicDataStepOne', {$state}); controller = $componentController('vnTicketBasicDataStepOne', {$state});
controller.ticket = { controller.ticket = {
addressFk: 121, addressFk: 121,
@ -37,6 +39,14 @@ describe('Ticket', () => {
}); });
}); });
describe('clientId() getter', () => {
it('should return the clientFk property', () => {
controller.ticket = {id: 1, clientFk: 102};
expect(controller.clientId).toEqual(102);
});
});
describe('clientId() setter', () => { describe('clientId() setter', () => {
it('should set clientId property and call onChangeClient() method ', () => { it('should set clientId property and call onChangeClient() method ', () => {
spyOn(controller, 'onChangeClient'); spyOn(controller, 'onChangeClient');
@ -47,6 +57,69 @@ describe('Ticket', () => {
}); });
}); });
describe('adressId() getter', () => {
it('should return the addressFk property', () => {
controller.ticket = {id: 1, addressFk: 99};
expect(controller.addressId).toEqual(99);
});
});
describe('addressId() setter', () => {
it('should set addressId property and call getShipped() method ', () => {
spyOn(controller, 'getShipped');
controller.ticket.addressFk = 99;
controller.addressId = 100;
const landed = new Date();
const spectedResult = {
landed: landed,
addressFk: 100,
agencyModeFk: 7,
warehouseFk: 1
};
controller.landed = landed;
expect(controller.getShipped).toHaveBeenCalledWith(spectedResult);
expect(controller.ticket.addressFk).toEqual(100);
});
});
describe('warehouseId() getter', () => {
it('should return the warehouseId property', () => {
controller.ticket.warehouseFk = 2;
expect(controller.warehouseId).toEqual(2);
});
});
describe('warehouseId() setter', () => {
it('should set warehouseId property and call getShipped() method ', () => {
spyOn(controller, 'getShipped');
controller.ticket.warehouseId = 1;
controller.warehouseId = 2;
const landed = new Date();
const spectedResult = {
landed: landed,
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 2
};
controller.landed = landed;
expect(controller.getShipped).toHaveBeenCalledWith(spectedResult);
expect(controller.ticket.warehouseFk).toEqual(2);
});
});
describe('shipped() getter', () => {
it('should return the shipped property', () => {
const shipped = new Date();
controller.ticket.shipped = shipped;
expect(controller.shipped).toEqual(shipped);
});
});
describe('shipped() setter', () => { describe('shipped() setter', () => {
it('should set shipped property and call getLanded() method ', () => { it('should set shipped property and call getLanded() method ', () => {
spyOn(controller, 'getLanded'); spyOn(controller, 'getLanded');
@ -59,11 +132,19 @@ describe('Ticket', () => {
}; };
controller.shipped = shipped; controller.shipped = shipped;
expect(controller.getLanded).toHaveBeenCalledWith(spectedResult); expect(controller.getLanded).toHaveBeenCalledWith(spectedResult);
}); });
}); });
describe('landed() getter', () => {
it('should return the landed property', () => {
const landed = new Date();
controller.ticket.landed = landed;
expect(controller.landed).toEqual(landed);
});
});
describe('landed() setter', () => { describe('landed() setter', () => {
it('should set shipped property and call getShipped() method ', () => { it('should set shipped property and call getShipped() method ', () => {
spyOn(controller, 'getShipped'); spyOn(controller, 'getShipped');
@ -81,21 +162,29 @@ describe('Ticket', () => {
}); });
}); });
describe('agencyModeId() getter', () => {
it('should return the agencyModeFk property', () => {
controller.ticket.agencyModeFk = 66;
expect(controller.agencyModeId).toEqual(66);
});
});
describe('agencyModeId() setter', () => { describe('agencyModeId() setter', () => {
it('should set agencyModeId property and call onChangeAgencyMode() method', () => { it('should set agencyModeId property and call getLanded() method', () => {
spyOn(controller, 'getShipped'); spyOn(controller, 'getLanded');
const landed = new Date(); const shipped = new Date();
const agencyModeId = 8; const agencyModeId = 8;
const spectedResult = { const spectedResult = {
landed: landed, shipped: shipped,
addressFk: 121, addressFk: 121,
agencyModeFk: agencyModeId, agencyModeFk: agencyModeId,
warehouseFk: 1 warehouseFk: 1
}; };
controller.ticket.landed = landed; controller.ticket.shipped = shipped;
controller.agencyModeId = 8; controller.agencyModeId = 8;
expect(controller.getShipped).toHaveBeenCalledWith(spectedResult); expect(controller.getLanded).toHaveBeenCalledWith(spectedResult);
}); });
it('should do nothing if attempting to set the same agencyMode id', () => { it('should do nothing if attempting to set the same agencyMode id', () => {
@ -115,6 +204,14 @@ describe('Ticket', () => {
}); });
}); });
describe('zoneId() getter', () => {
it('should return the zoneFk property', () => {
controller.ticket.zoneFk = 10;
expect(controller.zoneId).toEqual(10);
});
});
describe('zoneId() setter', () => { describe('zoneId() setter', () => {
it('should set zoneId property and call onChangeZone() method ', () => { it('should set zoneId property and call onChangeZone() method ', () => {
const zoneId = 5; const zoneId = 5;
@ -223,5 +320,49 @@ describe('Ticket', () => {
$httpBackend.flush(); $httpBackend.flush();
}); });
}); });
describe('getLanded()', () => {
it('should return an available landed date', async() => {
const shipped = new Date();
const expectedResult = {landed: new Date()};
const params = {
shipped: shipped,
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 1
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `/api/Agencies/getLanded?${serializedParams}`).respond(200, expectedResult);
$httpBackend.expect('GET', `/api/Agencies/getLanded?${serializedParams}`);
controller.getLanded(params);
$httpBackend.flush();
expect(controller.shipped).toEqual(shipped);
expect(controller.landed).toEqual(expectedResult.landed);
});
});
describe('getShipped()', () => {
it('should return an available shipped date', async() => {
const landed = new Date();
const expectedResult = {shipped: new Date()};
const params = {
landed: landed,
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 1
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200, expectedResult);
$httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
controller.getShipped(params);
$httpBackend.flush();
expect(controller.shipped).toEqual(expectedResult.shipped);
expect(controller.landed).toEqual(landed);
});
});
}); });
}); });