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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|