2019-10-25 11:29:05 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Travel Component vnTravelIndex', () => {
|
|
|
|
let $componentController;
|
|
|
|
let controller;
|
2019-12-20 06:55:00 +00:00
|
|
|
let $window;
|
|
|
|
let travels = [{
|
|
|
|
id: 1,
|
|
|
|
warehouseInFk: 1,
|
|
|
|
totalEntries: 3,
|
|
|
|
isDelivered: false
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
warehouseInFk: 1,
|
|
|
|
total: 4,
|
|
|
|
isDelivered: true
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
warehouseInFk: 1,
|
|
|
|
total: 2,
|
|
|
|
isDelivered: true
|
|
|
|
}];
|
2019-10-25 11:29:05 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.module('travel', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
2019-10-25 11:29:05 +00:00
|
|
|
$componentController = _$componentController_;
|
2019-12-20 06:55:00 +00:00
|
|
|
let $scope = $rootScope.$new();
|
|
|
|
controller = $componentController('vnTravelIndex', $scope);
|
|
|
|
controller.$.summary = {show: jasmine.createSpy('show')};
|
2019-10-25 11:29:05 +00:00
|
|
|
}));
|
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
describe('preview()', () => {
|
|
|
|
it('should show the dialog summary', () => {
|
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
controller.preview(event, travels[0]);
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
2019-10-25 11:29:05 +00:00
|
|
|
});
|
2019-12-20 06:55:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getScopeDates()', () => {
|
|
|
|
it('should return a range of dates', () => {
|
|
|
|
let days = 2; // never put 1 or anything higher than 2
|
|
|
|
let result = controller.getScopeDates(days);
|
|
|
|
|
|
|
|
let from = new Date(result.shippedFrom).getTime();
|
|
|
|
let to = new Date(result.shippedTo).getTime();
|
|
|
|
let range = to - from;
|
|
|
|
|
|
|
|
const dayInMilliseconds = 24 * 60 * 60 * 1000;
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
let millisecondsPerAddedDay = dayInMilliseconds - 1;
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
expect(range - dayInMilliseconds).toEqual(dayInMilliseconds + millisecondsPerAddedDay);
|
2019-10-25 11:29:05 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-10 13:09:26 +00:00
|
|
|
|
|
|
|
describe('onCloneAccept()', () => {
|
|
|
|
it('should do nothing if response is not accept', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
let response = 'ERROR!';
|
|
|
|
controller.travelSelected = 'check me';
|
|
|
|
|
|
|
|
controller.onCloneAccept(response);
|
|
|
|
|
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith();
|
|
|
|
expect(controller.travelSelected).toEqual('check me');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should do nothing if response is accept but travelSelected is not defined in the controller', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
let response = 'accept';
|
|
|
|
controller.travelSelected = undefined;
|
|
|
|
|
|
|
|
controller.onCloneAccept(response);
|
|
|
|
|
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith();
|
|
|
|
expect(controller.travelSelected).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call go() then update travelSelected in the controller', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
let response = 'accept';
|
|
|
|
controller.travelSelected = {
|
|
|
|
ref: 1,
|
|
|
|
agencyFk: 1};
|
|
|
|
const travel = {
|
|
|
|
ref: controller.travelSelected.ref,
|
|
|
|
agencyModeFk: controller.travelSelected.agencyFk
|
|
|
|
};
|
|
|
|
const queryParams = JSON.stringify(travel);
|
|
|
|
controller.onCloneAccept(response);
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams});
|
|
|
|
expect(controller.travelSelected).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
2019-10-25 11:29:05 +00:00
|
|
|
});
|