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) {
|
||||
if (!Object.entries($params).length)
|
||||
const hasEntries = Object.entries($params).length;
|
||||
if (!hasEntries)
|
||||
$params.scopeDays = 1;
|
||||
|
||||
if (typeof $params.scopeDays === 'number') {
|
||||
|
|
|
@ -12,20 +12,50 @@ describe('Route Component vnRoute', () => {
|
|||
|
||||
describe('fetchParams()', () => {
|
||||
it('should return a range of dates with passed scope 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 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);
|
||||
|
||||
let params = controller.fetchParams({scopeDays: 2});
|
||||
const diff = diffInDays(
|
||||
params.from,
|
||||
new Date(params.to.getTime() + 1)
|
||||
);
|
||||
const expectedParams = ({
|
||||
from,
|
||||
scopeDays: params.scopeDays,
|
||||
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