salix/modules/ticket/front/basic-data/step-one/index.spec.js

248 lines
8.9 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-08-09 12:42:02 +00:00
describe('Ticket', () => {
describe('Component vnTicketBasicDataStepOne', () => {
let $state;
let controller;
let $httpBackend;
2019-05-30 06:41:08 +00:00
let $httpParamSerializer;
beforeEach(ngModule('ticket'));
2019-05-30 06:41:08 +00:00
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
$state = _$state_;
$httpBackend = _$httpBackend_;
2019-05-30 06:41:08 +00:00
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnTicketBasicDataStepOne', {$state});
}));
describe('ticket() setter', () => {
it('should set ticket property and call onChangeClient() method', () => {
spyOn(controller, 'onChangeClient');
controller.ticket = {id: 1, clientFk: 101};
expect(controller.onChangeClient).toHaveBeenCalledWith(101);
});
});
describe('clientId() setter', () => {
it('should set clientId property and call onChangeClient() method ', () => {
spyOn(controller, 'onChangeClient');
controller.ticket = {id: 1, clientId: 101};
controller.clientId = 102;
expect(controller.onChangeClient).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
});
});
describe('landed() setter', () => {
it('should set landed property and call onChangeLanded() method ', () => {
2018-08-22 10:55:13 +00:00
let landed = new Date();
spyOn(controller, 'onChangeLanded');
controller.ticket = {id: 1};
2018-08-22 10:55:13 +00:00
controller.landed = landed;
2018-08-22 10:55:13 +00:00
expect(controller.onChangeLanded).toHaveBeenCalledWith(landed);
});
});
describe('agencyModeId() setter', () => {
it('should set agencyModeId property and call onChangeAgencyMode() method ', () => {
const agencyModeId = 8;
spyOn(controller, 'onChangeAgencyMode');
controller.ticket = {id: 1};
controller.agencyModeId = 8;
expect(controller.onChangeAgencyMode).toHaveBeenCalledWith(agencyModeId);
});
});
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);
});
});
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));
$httpBackend.when('GET', `/api/Clients/${clientId}/addresses?filter=${filter}`).respond(200);
$httpBackend.expect('GET', `/api/Clients/${clientId}/addresses?filter=${filter}`);
controller.onChangeClient(clientId);
$httpBackend.flush();
});
});
2018-08-16 11:12:18 +00:00
describe('onChangeShipped()', () => {
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 = {
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();
});
});
describe('onChangeLanded()', () => {
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-08-22 10:55:13 +00:00
controller.onChangeLanded(landed);
$httpBackend.flush();
});
});
describe('onChangeZone()', () => {
it('should return an available zone', async() => {
const zoneId = 5;
$httpBackend.when('GET', `/api/Zones/${zoneId}`).respond(200);
$httpBackend.expect('GET', `/api/Zones/${zoneId}`);
controller.onChangeZone(zoneId);
$httpBackend.flush();
});
});
describe('onChangeAgencyMode()', () => {
it('should return an available agency', async() => {
const landed = new Date();
const agencyModeId = 7;
controller._ticket = {
id: 1,
landed: landed,
addressFk: 121,
agencyModeFk: agencyModeId,
warehouseFk: 1
};
let params = {
landed: landed,
addressFk: 121,
agencyModeFk: agencyModeId,
warehouseFk: 1
};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200);
$httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
controller.onChangeAgencyMode(agencyModeId);
$httpBackend.flush();
});
});
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,
zoneFk: 3,
2018-05-22 06:14:16 +00:00
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date(),
landed: new Date()
};
2018-05-22 06:14:16 +00:00
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,
zoneFk: 3,
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date(),
landed: landed
2018-05-22 06:14:16 +00:00
};
let response = {error: new Error('NO_AGENCY_AVAILABLE')};
$httpBackend.whenPOST(`/api/tickets/1/priceDifference`).respond(400, response);
$httpBackend.expectPOST(`/api/tickets/1/priceDifference`);
controller.onStepChange();
2018-05-22 06:14:16 +00:00
$httpBackend.flush();
});
});
});
});