2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-08-09 12:42:02 +00:00
|
|
|
describe('Ticket', () => {
|
2019-04-16 13:00:21 +00:00
|
|
|
describe('Component vnTicketBasicDataStepOne', () => {
|
2018-05-16 06:13:39 +00:00
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2019-10-04 07:28:09 +00:00
|
|
|
let $httpParamSerializer;
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
2018-05-16 06:13:39 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2019-10-04 07:28:09 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2019-04-16 13:00:21 +00:00
|
|
|
controller = $componentController('vnTicketBasicDataStepOne', {$state});
|
2019-09-04 06:04:31 +00:00
|
|
|
controller.ticket = {
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 7,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2018-05-16 06:13:39 +00:00
|
|
|
}));
|
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
describe('ticket() setter', () => {
|
2019-07-26 09:48:01 +00:00
|
|
|
it('should set ticket property and call onChangeClient() method', () => {
|
|
|
|
spyOn(controller, 'onChangeClient');
|
2018-07-11 07:11:45 +00:00
|
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
expect(controller.onChangeClient).toHaveBeenCalledWith(101);
|
2018-07-11 07:11:45 +00:00
|
|
|
});
|
2019-08-20 12:18:32 +00:00
|
|
|
|
|
|
|
it(`should not call onChangeClient() method as the ticket doesn't have an ID`, () => {
|
|
|
|
spyOn(controller, 'onChangeClient');
|
|
|
|
controller.ticket = {};
|
|
|
|
|
|
|
|
expect(controller.onChangeClient).not.toHaveBeenCalledWith();
|
|
|
|
});
|
2018-07-11 07:11:45 +00:00
|
|
|
});
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
describe('clientId() getter', () => {
|
|
|
|
it('should return the clientFk property', () => {
|
|
|
|
controller.ticket = {id: 1, clientFk: 102};
|
|
|
|
|
|
|
|
expect(controller.clientId).toEqual(102);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
describe('clientId() setter', () => {
|
|
|
|
it('should set clientId property and call onChangeClient() method ', () => {
|
|
|
|
spyOn(controller, 'onChangeClient');
|
|
|
|
controller.ticket = {id: 1, clientId: 101};
|
|
|
|
controller.clientId = 102;
|
2018-07-11 07:11:45 +00:00
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
expect(controller.onChangeClient).toHaveBeenCalledWith(102);
|
2018-07-24 10:14:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
describe('shipped() setter', () => {
|
2019-09-04 06:04:31 +00:00
|
|
|
it('should set shipped property and call getLanded() method ', () => {
|
|
|
|
spyOn(controller, 'getLanded');
|
|
|
|
const shipped = new Date();
|
|
|
|
const spectedResult = {
|
|
|
|
shipped: shipped,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 7,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.shipped = shipped;
|
2018-08-16 11:12:18 +00:00
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
expect(controller.getLanded).toHaveBeenCalledWith(spectedResult);
|
2018-08-16 11:12:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
describe('landed() getter', () => {
|
|
|
|
it('should return the landed property', () => {
|
|
|
|
const landed = new Date();
|
|
|
|
controller.ticket.landed = landed;
|
|
|
|
|
|
|
|
expect(controller.landed).toEqual(landed);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
describe('landed() setter', () => {
|
2019-09-04 06:04:31 +00:00
|
|
|
it('should set shipped property and call getShipped() method ', () => {
|
|
|
|
spyOn(controller, 'getShipped');
|
|
|
|
const landed = new Date();
|
|
|
|
const spectedResult = {
|
|
|
|
landed: landed,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 7,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.landed = landed;
|
2018-07-24 10:14:35 +00:00
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
|
|
|
|
expect(controller.getShipped).toHaveBeenCalledWith(spectedResult);
|
2018-07-24 10:14:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
describe('agencyModeId() getter', () => {
|
|
|
|
it('should return the agencyModeFk property', () => {
|
|
|
|
controller.ticket.agencyModeFk = 66;
|
|
|
|
|
|
|
|
expect(controller.agencyModeId).toEqual(66);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
describe('agencyModeId() setter', () => {
|
2019-10-04 07:28:09 +00:00
|
|
|
it('should set agencyModeId property and call getLanded() method', () => {
|
|
|
|
spyOn(controller, 'getLanded');
|
|
|
|
const shipped = new Date();
|
2019-07-26 09:48:01 +00:00
|
|
|
const agencyModeId = 8;
|
2019-09-04 06:04:31 +00:00
|
|
|
const spectedResult = {
|
2019-10-04 07:28:09 +00:00
|
|
|
shipped: shipped,
|
2019-09-04 06:04:31 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: agencyModeId,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2019-10-04 07:28:09 +00:00
|
|
|
controller.ticket.shipped = shipped;
|
2019-07-26 09:48:01 +00:00
|
|
|
controller.agencyModeId = 8;
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
expect(controller.getLanded).toHaveBeenCalledWith(spectedResult);
|
2019-07-26 09:48:01 +00:00
|
|
|
});
|
2019-08-20 12:18:32 +00:00
|
|
|
|
|
|
|
it('should do nothing if attempting to set the same agencyMode id', () => {
|
2019-09-04 06:04:31 +00:00
|
|
|
spyOn(controller, 'getShipped');
|
|
|
|
const landed = new Date();
|
|
|
|
const agencyModeId = 7;
|
|
|
|
const spectedResult = {
|
|
|
|
landed: landed,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: agencyModeId,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
|
|
|
controller.ticket.landed = landed;
|
|
|
|
controller.agencyModeId = 7;
|
2019-08-20 12:18:32 +00:00
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
expect(controller.getShipped).not.toHaveBeenCalledWith(spectedResult);
|
2019-08-20 12:18:32 +00:00
|
|
|
});
|
2019-07-26 09:48:01 +00:00
|
|
|
});
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
describe('zoneId() getter', () => {
|
|
|
|
it('should return the zoneFk property', () => {
|
|
|
|
controller.ticket.zoneFk = 10;
|
|
|
|
|
|
|
|
expect(controller.zoneId).toEqual(10);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
describe('zoneId() setter', () => {
|
|
|
|
it('should set zoneId property and call onChangeZone() method ', () => {
|
|
|
|
const zoneId = 5;
|
|
|
|
spyOn(controller, 'onChangeZone');
|
|
|
|
controller.ticket = {id: 1};
|
|
|
|
controller.zoneId = 5;
|
|
|
|
|
|
|
|
expect(controller.onChangeZone).toHaveBeenCalledWith(zoneId);
|
|
|
|
});
|
2019-08-20 12:18:32 +00:00
|
|
|
|
|
|
|
it('should do nothing if attempting to set the same zone id', () => {
|
|
|
|
const zoneId = 5;
|
|
|
|
spyOn(controller, 'onChangeZone');
|
|
|
|
controller.ticket = {id: 1, zoneFk: zoneId};
|
|
|
|
controller.zoneId = zoneId;
|
|
|
|
|
|
|
|
expect(controller.onChangeZone).not.toHaveBeenCalledWith(zoneId);
|
|
|
|
});
|
2019-07-26 09:48:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangeClient()', () => {
|
|
|
|
it('should return a list of addresses from choosed client', async() => {
|
|
|
|
const clientId = 102;
|
|
|
|
let filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'province',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Clients/${clientId}/addresses?filter=${filter}`).respond(200);
|
|
|
|
$httpBackend.expect('GET', `Clients/${clientId}/addresses?filter=${filter}`);
|
2019-07-26 09:48:01 +00:00
|
|
|
controller.onChangeClient(clientId);
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangeZone()', () => {
|
|
|
|
it('should return an available zone', async() => {
|
|
|
|
const zoneId = 5;
|
2019-08-20 12:18:32 +00:00
|
|
|
const landed = new Date();
|
|
|
|
controller._ticket = {
|
|
|
|
id: 1,
|
|
|
|
landed: landed,
|
|
|
|
addressFk: 121,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2019-07-26 09:48:01 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Zones/${zoneId}`).respond(200);
|
|
|
|
$httpBackend.expect('GET', `Zones/${zoneId}`);
|
2019-07-26 09:48:01 +00:00
|
|
|
controller.onChangeZone(zoneId);
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-16 06:13:39 +00:00
|
|
|
describe('isFormInvalid()', () => {
|
|
|
|
it('should check if all form fields are valid', () => {
|
|
|
|
controller.ticket = {
|
2018-05-22 06:14:16 +00:00
|
|
|
clientFk: 1,
|
|
|
|
addressFk: 121,
|
2019-07-26 09:48:01 +00:00
|
|
|
zoneFk: 3,
|
2018-05-22 06:14:16 +00:00
|
|
|
agencyModeFk: 1,
|
|
|
|
companyFk: 442,
|
2018-05-30 08:55:54 +00:00
|
|
|
warehouseFk: 1,
|
2018-05-25 08:03:45 +00:00
|
|
|
shipped: new Date(),
|
|
|
|
landed: new Date()
|
2018-05-16 06:13:39 +00:00
|
|
|
};
|
2018-05-22 06:14:16 +00:00
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
expect(controller.isFormInvalid()).toBeFalsy();
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onStepChange()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should call onStepChange method and return a NO_AGENCY_AVAILABLE signal error', async() => {
|
2018-05-25 15:25:35 +00:00
|
|
|
let landed = new Date();
|
|
|
|
landed.setHours(0, 0, 0, 0);
|
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
controller._ticket = {
|
2018-05-16 06:13:39 +00:00
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
|
|
|
addressFk: 121,
|
2019-07-26 09:48:01 +00:00
|
|
|
zoneFk: 3,
|
2018-05-16 06:13:39 +00:00
|
|
|
agencyModeFk: 1,
|
|
|
|
companyFk: 442,
|
2018-05-30 08:55:54 +00:00
|
|
|
warehouseFk: 1,
|
2018-05-25 08:03:45 +00:00
|
|
|
shipped: new Date(),
|
2018-05-25 15:25:35 +00:00
|
|
|
landed: landed
|
2018-05-22 06:14:16 +00:00
|
|
|
};
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-05-25 15:25:35 +00:00
|
|
|
let response = {error: new Error('NO_AGENCY_AVAILABLE')};
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenPOST(`tickets/1/priceDifference`).respond(400, response);
|
|
|
|
$httpBackend.expectPOST(`tickets/1/priceDifference`);
|
2018-05-25 15:25:35 +00:00
|
|
|
controller.onStepChange();
|
2018-05-22 06:14:16 +00:00
|
|
|
$httpBackend.flush();
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|
2019-10-04 07:28:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Agencies/getLanded?${serializedParams}`).respond(200, expectedResult);
|
|
|
|
$httpBackend.expect('GET', `Agencies/getLanded?${serializedParams}`);
|
2019-10-04 07:28:09 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Agencies/getShipped?${serializedParams}`).respond(200, expectedResult);
|
|
|
|
$httpBackend.expect('GET', `Agencies/getShipped?${serializedParams}`);
|
2019-10-04 07:28:09 +00:00
|
|
|
controller.getShipped(params);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.shipped).toEqual(expectedResult.shipped);
|
|
|
|
expect(controller.landed).toEqual(landed);
|
|
|
|
});
|
|
|
|
});
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
2018-05-25 15:25:35 +00:00
|
|
|
});
|