2020-03-16 17:08:44 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Travel Component vnTravel', () => {
|
|
|
|
let controller;
|
|
|
|
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject($componentController => {
|
2020-03-16 17:08:44 +00:00
|
|
|
let $element = angular.element(`<div></div>`);
|
|
|
|
controller = $componentController('vnTravel', {$element});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('fetchParams()', () => {
|
|
|
|
it('should return a range of dates with passed scope days', () => {
|
2020-03-27 11:01:09 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2020-03-27 11:01:09 +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
|
|
|
|
2020-03-27 11:01:09 +00:00
|
|
|
expect(diff).toEqual(3);
|
2020-03-16 17:08:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|