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

41 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-16 17:08:44 +00:00
import './index.js';
describe('Travel Component vnTravel', () => {
let controller;
beforeEach(ngModule('travel'));
beforeEach(angular.mock.inject($componentController => {
let $element = angular.element(`<div></div>`);
controller = $componentController('vnTravel', {$element});
}));
describe('fetchParams()', () => {
it('should return a range of dates with passed scope days', () => {
/**
* Calculates the difference in days between two dates, it also
* accounts for cases where the two dates in question span a
* daylight saving time (DST) change.
*
* @param {Date} a The start date
* @param {Date} b The end date
* @return {Number} The difference in days
*/
function diffInDays(a, b) {
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
const msInDay = 86400 * 1000;
return Math.floor((utc2 - utc1) / msInDay);
}
2020-03-16 17:08:44 +00:00
let params = controller.fetchParams({scopeDays: 2});
const diff = diffInDays(
params.shippedFrom,
new Date(params.shippedTo.getTime() + 1)
);
2020-03-16 17:08:44 +00:00
expect(diff).toEqual(3);
2020-03-16 17:08:44 +00:00
});
});
});