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-05-30 06:41:08 +00:00
|
|
|
let $httpParamSerializer;
|
|
|
|
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2019-05-30 06:41:08 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
2018-05-16 06:13:39 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2019-05-30 06:41:08 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2019-04-16 13:00:21 +00:00
|
|
|
controller = $componentController('vnTicketBasicDataStepOne', {$state});
|
2018-05-16 06:13:39 +00:00
|
|
|
}));
|
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
describe('ticket() setter', () => {
|
2018-08-09 12:42:02 +00:00
|
|
|
it('should set ticket property and call onChangeAddress() method', () => {
|
2018-07-24 10:14:35 +00:00
|
|
|
spyOn(controller, 'onChangeAddress');
|
2018-07-11 07:11:45 +00:00
|
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
expect(controller.onChangeAddress).toHaveBeenCalledWith(101);
|
2018-07-11 07:11:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clientFk() setter', () => {
|
2018-07-24 10:14:35 +00:00
|
|
|
it('should set clientFk property and call onChangeAddress() method ', () => {
|
|
|
|
spyOn(controller, 'onChangeAddress');
|
2018-07-11 07:11:45 +00:00
|
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
controller.clientFk = 102;
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
expect(controller.onChangeAddress).toHaveBeenCalledWith(102);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
describe('shipped() setter', () => {
|
|
|
|
it('should set shipped property and call onChangeShipped() method ', () => {
|
2018-08-22 10:55:13 +00:00
|
|
|
let shipped = new Date();
|
2018-08-16 11:12:18 +00:00
|
|
|
spyOn(controller, 'onChangeShipped');
|
|
|
|
controller.ticket = {id: 1};
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.shipped = shipped;
|
2018-08-16 11:12:18 +00:00
|
|
|
|
2018-08-22 10:55:13 +00:00
|
|
|
expect(controller.onChangeShipped).toHaveBeenCalledWith(shipped);
|
2018-08-16 11:12:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
describe('landed() setter', () => {
|
|
|
|
it('should set landed property and call onChangeLanded() method ', () => {
|
2018-08-22 10:55:13 +00:00
|
|
|
let landed = new Date();
|
2018-07-24 10:14:35 +00:00
|
|
|
spyOn(controller, 'onChangeLanded');
|
|
|
|
controller.ticket = {id: 1};
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.landed = landed;
|
2018-07-24 10:14:35 +00:00
|
|
|
|
2018-08-22 10:55:13 +00:00
|
|
|
expect(controller.onChangeLanded).toHaveBeenCalledWith(landed);
|
2018-07-24 10:14:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
describe('onChangeShipped()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should return an available landing date', async() => {
|
2018-08-22 10:55:13 +00:00
|
|
|
let shipped = new Date();
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
controller._ticket = {
|
|
|
|
id: 1,
|
2018-08-22 10:55:13 +00:00
|
|
|
shipped: shipped,
|
2018-08-16 11:12:18 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
2019-05-30 06:41:08 +00:00
|
|
|
let params = {
|
2019-02-26 11:51:01 +00:00
|
|
|
shipped: shipped,
|
2018-08-16 11:12:18 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
|
|
|
|
2019-05-30 06:41:08 +00:00
|
|
|
let serializedParams = $httpParamSerializer(params);
|
|
|
|
$httpBackend.when('GET', `/api/Agencies/getLanded?${serializedParams}`).respond(200);
|
|
|
|
$httpBackend.expect('GET', `/api/Agencies/getLanded?${serializedParams}`);
|
|
|
|
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.onChangeShipped(shipped);
|
2018-08-16 11:12:18 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
describe('onChangeLanded()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should return an available shipment date', async() => {
|
2018-08-22 10:55:13 +00:00
|
|
|
let landed = new Date();
|
2019-05-30 06:41:08 +00:00
|
|
|
controller._ticket = {
|
|
|
|
id: 1,
|
|
|
|
landed: landed,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
|
|
|
let params = {
|
|
|
|
landed: landed,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
let serializedParams = $httpParamSerializer(params);
|
|
|
|
$httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200);
|
|
|
|
$httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
|
2018-07-24 10:14:35 +00:00
|
|
|
|
2018-08-22 10:55:13 +00:00
|
|
|
controller.onChangeLanded(landed);
|
2018-07-24 10:14:35 +00:00
|
|
|
$httpBackend.flush();
|
2018-07-11 07:11:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
2018-05-25 15:25:35 +00:00
|
|
|
$httpBackend.whenPOST(`/ticket/api/sales/1/priceDifference`).respond(400, response);
|
|
|
|
$httpBackend.expectPOST(`/ticket/api/sales/1/priceDifference`);
|
|
|
|
controller.onStepChange();
|
2018-05-22 06:14:16 +00:00
|
|
|
$httpBackend.flush();
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-25 15:25:35 +00:00
|
|
|
});
|