156 lines
5.5 KiB
JavaScript
156 lines
5.5 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTicketBasicDataStepOne', () => {
|
|
let $state;
|
|
let controller;
|
|
let $httpBackend;
|
|
let $httpParamSerializer;
|
|
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
|
$state = _$state_;
|
|
$httpBackend = _$httpBackend_;
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
controller = $componentController('vnTicketBasicDataStepOne', {$state});
|
|
}));
|
|
|
|
describe('ticket() setter', () => {
|
|
it('should set ticket property and call onChangeAddress() method', () => {
|
|
spyOn(controller, 'onChangeAddress');
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
expect(controller.onChangeAddress).toHaveBeenCalledWith(101);
|
|
});
|
|
});
|
|
|
|
describe('clientFk() setter', () => {
|
|
it('should set clientFk property and call onChangeAddress() method ', () => {
|
|
spyOn(controller, 'onChangeAddress');
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
controller.clientFk = 102;
|
|
|
|
expect(controller.onChangeAddress).toHaveBeenCalledWith(102);
|
|
});
|
|
});
|
|
|
|
describe('shipped() setter', () => {
|
|
it('should set shipped property and call onChangeShipped() method ', () => {
|
|
let shipped = new Date();
|
|
spyOn(controller, 'onChangeShipped');
|
|
controller.ticket = {id: 1};
|
|
controller.shipped = shipped;
|
|
|
|
expect(controller.onChangeShipped).toHaveBeenCalledWith(shipped);
|
|
});
|
|
});
|
|
|
|
describe('landed() setter', () => {
|
|
it('should set landed property and call onChangeLanded() method ', () => {
|
|
let landed = new Date();
|
|
spyOn(controller, 'onChangeLanded');
|
|
controller.ticket = {id: 1};
|
|
controller.landed = landed;
|
|
|
|
expect(controller.onChangeLanded).toHaveBeenCalledWith(landed);
|
|
});
|
|
});
|
|
|
|
describe('onChangeShipped()', () => {
|
|
it('should return an available landing date', async() => {
|
|
let shipped = new Date();
|
|
|
|
controller._ticket = {
|
|
id: 1,
|
|
shipped: shipped,
|
|
addressFk: 121,
|
|
agencyModeFk: 2,
|
|
warehouseFk: 1
|
|
};
|
|
let params = {
|
|
shipped: shipped,
|
|
addressFk: 121,
|
|
agencyModeFk: 2,
|
|
warehouseFk: 1
|
|
};
|
|
|
|
let serializedParams = $httpParamSerializer(params);
|
|
$httpBackend.when('GET', `/api/Agencies/getLanded?${serializedParams}`).respond(200);
|
|
$httpBackend.expect('GET', `/api/Agencies/getLanded?${serializedParams}`);
|
|
|
|
controller.onChangeShipped(shipped);
|
|
$httpBackend.flush();
|
|
});
|
|
});
|
|
|
|
describe('onChangeLanded()', () => {
|
|
it('should return an available shipment date', async() => {
|
|
let landed = new Date();
|
|
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}`);
|
|
|
|
controller.onChangeLanded(landed);
|
|
$httpBackend.flush();
|
|
});
|
|
});
|
|
|
|
describe('isFormInvalid()', () => {
|
|
it('should check if all form fields are valid', () => {
|
|
controller.ticket = {
|
|
clientFk: 1,
|
|
addressFk: 121,
|
|
agencyModeFk: 1,
|
|
companyFk: 442,
|
|
warehouseFk: 1,
|
|
shipped: new Date(),
|
|
landed: new Date()
|
|
};
|
|
|
|
expect(controller.isFormInvalid()).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
describe('onStepChange()', () => {
|
|
it('should call onStepChange method and return a NO_AGENCY_AVAILABLE signal error', async() => {
|
|
let landed = new Date();
|
|
landed.setHours(0, 0, 0, 0);
|
|
|
|
controller._ticket = {
|
|
id: 1,
|
|
clientFk: 1,
|
|
addressFk: 121,
|
|
agencyModeFk: 1,
|
|
companyFk: 442,
|
|
warehouseFk: 1,
|
|
shipped: new Date(),
|
|
landed: landed
|
|
};
|
|
|
|
let response = {error: new Error('NO_AGENCY_AVAILABLE')};
|
|
|
|
$httpBackend.whenPOST(`/ticket/api/sales/1/priceDifference`).respond(400, response);
|
|
$httpBackend.expectPOST(`/ticket/api/sales/1/priceDifference`);
|
|
controller.onStepChange();
|
|
$httpBackend.flush();
|
|
});
|
|
});
|
|
});
|
|
});
|