salix/modules/travel/front/index/index.spec.js

65 lines
1.9 KiB
JavaScript

import './index.js';
describe('Travel Component vnTravelIndex', () => {
let $componentController;
let controller;
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
}];
beforeEach(angular.mock.module('travel', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
let $scope = $rootScope.$new();
controller = $componentController('vnTravelIndex', $scope);
controller.$.summary = {show: jasmine.createSpy('show')};
}));
describe('preview()', () => {
it('should show the dialog summary', () => {
let event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
controller.preview(event, travels[0]);
expect(controller.$.summary.show).toHaveBeenCalledWith();
});
});
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;
let millisecondsPerAddedDay = dayInMilliseconds - 1;
expect(range - dayInMilliseconds).toEqual(dayInMilliseconds + millisecondsPerAddedDay);
});
});
});