This commit is contained in:
parent
c6e8498281
commit
69ef2c2e27
|
@ -14,6 +14,7 @@
|
|||
label="Client"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}"
|
||||
field="$ctrl.clientId"
|
||||
initial-data="$ctrl.clientId"
|
||||
order="id">
|
||||
|
@ -23,7 +24,7 @@
|
|||
label="Address"
|
||||
show-field="nickname"
|
||||
value-field="id"
|
||||
field="$ctrl.ticket.addressFk"
|
||||
field="$ctrl.addressId"
|
||||
order="isActive DESC">
|
||||
<tpl-item ng-class="::{notActive: isActive === false}">
|
||||
<span class="inactive" translate>{{::isActive ? '' : 'INACTIVE'}}</span> {{::nickname}}
|
||||
|
|
|
@ -26,10 +26,7 @@ class Controller {
|
|||
}
|
||||
|
||||
get clientId() {
|
||||
if (this.ticket)
|
||||
return this.ticket.clientFk;
|
||||
|
||||
return null;
|
||||
return this.ticket && this.ticket.clientFk;
|
||||
}
|
||||
|
||||
set clientId(value) {
|
||||
|
@ -39,11 +36,24 @@ class Controller {
|
|||
this.onChangeClient(value);
|
||||
}
|
||||
|
||||
get warehouseId() {
|
||||
if (this.ticket)
|
||||
return this.ticket.warehouseFk;
|
||||
get addressId() {
|
||||
return this.ticket && this.ticket.addressFk;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -60,10 +70,7 @@ class Controller {
|
|||
|
||||
|
||||
get shipped() {
|
||||
if (this.ticket)
|
||||
return this.ticket.shipped;
|
||||
|
||||
return null;
|
||||
return this.ticket && this.ticket.shipped;
|
||||
}
|
||||
|
||||
set shipped(value) {
|
||||
|
@ -77,10 +84,7 @@ class Controller {
|
|||
}
|
||||
|
||||
get landed() {
|
||||
if (this.ticket)
|
||||
return this.ticket.landed;
|
||||
|
||||
return null;
|
||||
return this.ticket && this.ticket.landed;
|
||||
}
|
||||
|
||||
set landed(value) {
|
||||
|
@ -94,17 +98,14 @@ class Controller {
|
|||
}
|
||||
|
||||
get agencyModeId() {
|
||||
if (this.ticket)
|
||||
return this.ticket.agencyModeFk;
|
||||
|
||||
return null;
|
||||
return this.ticket && this.ticket.agencyModeFk;
|
||||
}
|
||||
|
||||
set agencyModeId(value) {
|
||||
if (value != this.ticket.agencyModeFk) {
|
||||
this.ticket.agencyModeFk = value;
|
||||
this.getShipped({
|
||||
landed: this.ticket.landed,
|
||||
this.getLanded({
|
||||
shipped: this.ticket.shipped,
|
||||
addressFk: this.ticket.addressFk,
|
||||
agencyModeFk: value,
|
||||
warehouseFk: this.ticket.warehouseFk
|
||||
|
@ -113,10 +114,7 @@ class Controller {
|
|||
}
|
||||
|
||||
get zoneId() {
|
||||
if (this.ticket)
|
||||
return this.ticket.zoneFk;
|
||||
|
||||
return null;
|
||||
return this.ticket && this.ticket.zoneFk;
|
||||
}
|
||||
|
||||
set zoneId(value) {
|
||||
|
@ -206,9 +204,10 @@ class Controller {
|
|||
this.$http.get(query, {params}).then(res => {
|
||||
if (res.data) {
|
||||
this.ticket.zoneFk = res.data.zoneFk;
|
||||
this.ticket.landed = res.data.landed;
|
||||
this.ticket.agencyModeFk = res.data.agencyModeFk;
|
||||
this.ticket.warehouseFk = res.data.warehouseFk;
|
||||
this.ticket.landed = res.data.landed;
|
||||
this.ticket.shipped = params.shipped;
|
||||
} else {
|
||||
return this.vnApp.showError(
|
||||
this.$translate.instant(`No delivery zone available for this landing date`)
|
||||
|
@ -226,9 +225,10 @@ class Controller {
|
|||
this.$http.get(query, {params}).then(res => {
|
||||
if (res.data) {
|
||||
this.ticket.zoneFk = res.data.zoneFk;
|
||||
this.ticket.shipped = res.data.shipped;
|
||||
this.ticket.agencyModeFk = res.data.agencyModeFk;
|
||||
this.ticket.warehouseFk = res.data.warehouseFk;
|
||||
this.ticket.landed = params.landed;
|
||||
this.ticket.shipped = res.data.shipped;
|
||||
} else {
|
||||
return this.vnApp.showError(
|
||||
this.$translate.instant(`No delivery zone available for this landing date`)
|
||||
|
|
|
@ -5,14 +5,16 @@ describe('Ticket', () => {
|
|||
let $state;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $httpParamSerializer;
|
||||
|
||||
beforeEach(angular.mock.module('ticket', $translateProvider => {
|
||||
$translateProvider.translations('en', {});
|
||||
}));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$state = _$state_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnTicketBasicDataStepOne', {$state});
|
||||
controller.ticket = {
|
||||
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', () => {
|
||||
it('should set clientId property and call onChangeClient() method ', () => {
|
||||
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', () => {
|
||||
it('should set shipped property and call getLanded() method ', () => {
|
||||
spyOn(controller, 'getLanded');
|
||||
|
@ -59,11 +132,19 @@ describe('Ticket', () => {
|
|||
};
|
||||
controller.shipped = shipped;
|
||||
|
||||
|
||||
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', () => {
|
||||
it('should set shipped property and call getShipped() method ', () => {
|
||||
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', () => {
|
||||
it('should set agencyModeId property and call onChangeAgencyMode() method', () => {
|
||||
spyOn(controller, 'getShipped');
|
||||
const landed = new Date();
|
||||
it('should set agencyModeId property and call getLanded() method', () => {
|
||||
spyOn(controller, 'getLanded');
|
||||
const shipped = new Date();
|
||||
const agencyModeId = 8;
|
||||
const spectedResult = {
|
||||
landed: landed,
|
||||
shipped: shipped,
|
||||
addressFk: 121,
|
||||
agencyModeFk: agencyModeId,
|
||||
warehouseFk: 1
|
||||
};
|
||||
controller.ticket.landed = landed;
|
||||
controller.ticket.shipped = shipped;
|
||||
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', () => {
|
||||
|
@ -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', () => {
|
||||
it('should set zoneId property and call onChangeZone() method ', () => {
|
||||
const zoneId = 5;
|
||||
|
@ -223,5 +320,49 @@ describe('Ticket', () => {
|
|||
$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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue