Rework the test on main section
This commit is contained in:
parent
e205ebba72
commit
bef8fca529
|
@ -11,7 +11,8 @@ export default class Route extends ModuleMain {
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchParams($params) {
|
fetchParams($params) {
|
||||||
if (!Object.entries($params).length)
|
const hasEntries = Object.entries($params).length;
|
||||||
|
if (!hasEntries)
|
||||||
$params.scopeDays = 1;
|
$params.scopeDays = 1;
|
||||||
|
|
||||||
if (typeof $params.scopeDays === 'number') {
|
if (typeof $params.scopeDays === 'number') {
|
||||||
|
|
|
@ -12,20 +12,50 @@ describe('Route Component vnRoute', () => {
|
||||||
|
|
||||||
describe('fetchParams()', () => {
|
describe('fetchParams()', () => {
|
||||||
it('should return a range of dates with passed scope days', () => {
|
it('should return a range of dates with passed scope days', () => {
|
||||||
function diffInDays(a, b) {
|
let params = controller.fetchParams({
|
||||||
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
|
scopeDays: 2
|
||||||
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
|
});
|
||||||
const msInDay = 86400 * 1000;
|
const from = new Date();
|
||||||
return Math.floor((utc2 - utc1) / msInDay);
|
from.setHours(0, 0, 0, 0);
|
||||||
}
|
const to = new Date(from.getTime());
|
||||||
|
to.setDate(to.getDate() + params.scopeDays);
|
||||||
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
let params = controller.fetchParams({scopeDays: 2});
|
const expectedParams = ({
|
||||||
const diff = diffInDays(
|
from,
|
||||||
params.from,
|
scopeDays: params.scopeDays,
|
||||||
new Date(params.to.getTime() + 1)
|
to
|
||||||
);
|
});
|
||||||
|
|
||||||
expect(diff).toEqual(3);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when scope days has a string value', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 'prueba'
|
||||||
|
});
|
||||||
|
if (typeof params.scopeDays !== 'number')
|
||||||
|
|
||||||
|
expect(params.scopeDays).toBe('prueba');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue