41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
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);
|
|
}
|
|
|
|
let params = controller.fetchParams({scopeDays: 2});
|
|
const diff = diffInDays(
|
|
params.shippedFrom,
|
|
new Date(params.shippedTo.getTime() + 1)
|
|
);
|
|
|
|
expect(diff).toEqual(3);
|
|
});
|
|
});
|
|
});
|