2019-12-09 11:15:19 +00:00
|
|
|
import './index';
|
|
|
|
import watcher from 'core/mocks/watcher';
|
|
|
|
|
|
|
|
describe('Travel Component vnTravelCreate', () => {
|
|
|
|
let $scope;
|
|
|
|
let $state;
|
|
|
|
let controller;
|
2021-02-10 07:47:58 +00:00
|
|
|
let $httpBackend;
|
2019-12-09 11:15:19 +00:00
|
|
|
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
|
2021-02-10 07:47:58 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2019-12-09 11:15:19 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$state = _$state_;
|
|
|
|
$scope.watcher = watcher;
|
2020-03-18 11:55:22 +00:00
|
|
|
const $element = angular.element('<vn-travel-create></vn-travel-create>');
|
2019-12-09 11:15:19 +00:00
|
|
|
controller = $componentController('vnTravelCreate', {$element, $scope});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it(`should call submit() on the watcher then expect a callback`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn($state, 'go');
|
2019-12-09 11:15:19 +00:00
|
|
|
|
|
|
|
controller.onSubmit();
|
|
|
|
|
2020-12-28 13:53:26 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.card.basicData', {id: 1234});
|
2019-12-09 11:15:19 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-10 13:09:26 +00:00
|
|
|
|
|
|
|
describe('$onChanges()', () => {
|
2020-03-18 11:55:22 +00:00
|
|
|
it('should update the travel data when $params.q is defined', () => {
|
|
|
|
controller.$params = {q: '{"ref": 1,"agencyModeFk": 1}'};
|
2020-03-11 08:17:14 +00:00
|
|
|
|
|
|
|
const params = {q: '{"ref": 1, "agencyModeFk": 1}'};
|
|
|
|
const json = JSON.parse(params.q);
|
|
|
|
|
2020-03-10 13:09:26 +00:00
|
|
|
controller.$onChanges();
|
|
|
|
|
2020-03-11 11:03:55 +00:00
|
|
|
expect(controller.travel).toEqual(json);
|
2020-03-10 13:09:26 +00:00
|
|
|
});
|
|
|
|
});
|
2021-02-10 07:47:58 +00:00
|
|
|
|
|
|
|
fdescribe('onShippedChange()', () => {
|
|
|
|
it(`should do nothing if there's no agencyMode or the travel has filled properties.`, () => {
|
|
|
|
controller.agencyModeFk = {};
|
|
|
|
controller.landed = {landed: 'January 30,2021, 00:00:00'};
|
|
|
|
controller.warehouseInFk = {warehouseInFk: 4};
|
|
|
|
controller.warehouseOutFk = {warehouseOutFk: 4};
|
|
|
|
|
|
|
|
const landed = {landed: 'January 30,2021, 00:00:00'};
|
|
|
|
const warehouseIn = {warehouseInFk: 4};
|
|
|
|
const warehouseOut = {warehouseOutFk: 4};
|
|
|
|
const agencyModeFk = {};
|
|
|
|
|
|
|
|
expect(controller.agencyModeFk).toEqual(agencyModeFk);
|
|
|
|
expect(controller.landed).toEqual(landed);
|
|
|
|
expect(controller.warehouseInFk).toEqual(warehouseIn);
|
|
|
|
expect(controller.warehouseOutFk).toEqual(warehouseOut);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should do fill the fields when it's selected a date and agency.`, () => {
|
|
|
|
controller.travel = {
|
|
|
|
agencyModeFk: 4,
|
|
|
|
landed: 'January 30,2021, 00:00:00',
|
|
|
|
warehouseInFk: 4,
|
|
|
|
warehouseOutFk: 4
|
|
|
|
};
|
|
|
|
const params = {agencyModeFk: 4};
|
|
|
|
|
|
|
|
$httpBackend.expectGET(`travels/getTravelData`, params).respond({agencyModeFk: 4});
|
|
|
|
controller.onShippedChange();
|
|
|
|
// $httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.travel.agencyModeFk).toEqual(params.agencyModeFk);
|
|
|
|
});
|
|
|
|
});
|
2019-12-09 11:15:19 +00:00
|
|
|
});
|