2021-01-20 13:49:06 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Route Component vnRoute', () => {
|
|
|
|
let controller;
|
|
|
|
|
|
|
|
beforeEach(ngModule('route'));
|
|
|
|
|
|
|
|
beforeEach(inject($componentController => {
|
|
|
|
let $element = angular.element(`<div></div>`);
|
|
|
|
controller = $componentController('vnRoute', {$element});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('fetchParams()', () => {
|
|
|
|
it('should return a range of dates with passed scope days', () => {
|
2021-01-28 13:14:14 +00:00
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 2
|
|
|
|
});
|
|
|
|
const from = new Date();
|
|
|
|
from.setHours(0, 0, 0, 0);
|
|
|
|
const to = new Date(from.getTime());
|
|
|
|
to.setDate(to.getDate() + params.scopeDays);
|
|
|
|
to.setHours(23, 59, 59, 999);
|
|
|
|
|
|
|
|
const expectedParams = ({
|
|
|
|
from,
|
|
|
|
scopeDays: params.scopeDays,
|
|
|
|
to
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(params).toEqual(expectedParams);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a default value for scope days', () => {
|
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 0
|
|
|
|
});
|
|
|
|
if (!params || params.scopeDays == '0')
|
|
|
|
params.scopeDays = 1;
|
|
|
|
|
|
|
|
expect(params.scopeDays).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a number value in scope days', () => {
|
|
|
|
let params = controller.fetchParams({
|
|
|
|
scopeDays: 2
|
|
|
|
});
|
|
|
|
if (typeof params.scopeDays === 'number')
|
|
|
|
|
|
|
|
expect(params.scopeDays).toEqual(2);
|
|
|
|
});
|
|
|
|
|
2021-02-01 12:19:26 +00:00
|
|
|
it('should throw an error when scope days is not equal a number', () => {
|
2021-01-28 13:14:14 +00:00
|
|
|
let params = controller.fetchParams({
|
2021-02-01 12:13:18 +00:00
|
|
|
scopeDays: 'ScopeDayNoNumber'
|
2021-01-28 13:14:14 +00:00
|
|
|
});
|
|
|
|
if (typeof params.scopeDays !== 'number')
|
|
|
|
|
2021-02-01 12:13:18 +00:00
|
|
|
expect(params.scopeDays).toBe('ScopeDayNoNumber');
|
2021-01-20 13:49:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|