salix/client/ticket/src/data/step-one/index.spec.js

144 lines
5.2 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-08-16 11:12:18 +00:00
import {toJsonDate} from 'core/src/lib/date';
2018-08-09 12:42:02 +00:00
describe('Ticket', () => {
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_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnTicketDataStepOne', {$state: $state});
}));
describe('ticket() setter', () => {
2018-08-09 12:42:02 +00:00
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);
});
});
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);
});
});
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
};
let data = {
2018-08-22 10:55:13 +00:00
shipped: toJsonDate(shipped),
2018-08-16 11:12:18 +00:00
addressFk: 121,
agencyModeFk: 2,
warehouseFk: 1
};
$httpBackend.whenPOST(`/api/Tickets/getLanded`, data).respond(200);
$httpBackend.expectPOST(`/api/Tickets/getLanded`, data);
2018-08-22 10:55:13 +00:00
controller.onChangeShipped(shipped);
2018-08-16 11:12:18 +00:00
$httpBackend.flush();
});
});
describe('onChangeLanded()', () => {
2018-08-16 11:12:18 +00:00
it('should return an available shipment date', async () => {
2018-08-22 10:55:13 +00:00
let landed = new Date();
controller._ticket = {id: 1, landed: landed, addressFk: 121, agencyModeFk: 2};
let data = {landed: landed, addressFk: 121, agencyModeFk: 2};
$httpBackend.whenPOST(`/api/Tickets/getShipped`, data).respond(200);
$httpBackend.expectPOST(`/api/Tickets/getShipped`, data);
2018-08-22 10:55:13 +00:00
controller.onChangeLanded(landed);
$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,
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,
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(`/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();
});
});
});
});