2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-07-13 13:57:19 +00:00
|
|
|
describe('ticket', () => {
|
2018-05-16 06:13:39 +00:00
|
|
|
describe('Component vnTicketDataStepOne', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('ticket');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$state = _$state_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-05-25 15:25:35 +00:00
|
|
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
2018-05-16 06:13:39 +00:00
|
|
|
controller = $componentController('vnTicketDataStepOne', {$state: $state});
|
|
|
|
}));
|
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
describe('ticket() setter', () => {
|
|
|
|
it('should set ticket property and call onChange() method ', () => {
|
|
|
|
spyOn(controller, 'onChange');
|
|
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
|
|
|
|
expect(controller.onChange).toHaveBeenCalledWith(101);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clientFk() setter', () => {
|
|
|
|
it('should set clientFk property and call onChange() method ', () => {
|
|
|
|
spyOn(controller, 'onChange');
|
|
|
|
controller.ticket = {id: 1, clientFk: 101};
|
|
|
|
controller.clientFk = 102;
|
|
|
|
|
|
|
|
expect(controller.onChange).toHaveBeenCalledWith(102);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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()', () => {
|
|
|
|
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
|
|
|
});
|