salix/modules/travel/front/main/index.spec.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

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', () => {
2021-01-29 10:45:35 +00:00
let params = controller.fetchParams({
scopeDays: 2
});
const shippedFrom = new Date();
shippedFrom.setHours(0, 0, 0, 0);
const shippedTo = new Date(shippedFrom.getTime());
shippedTo.setDate(shippedTo.getDate() + params.scopeDays);
shippedTo.setHours(23, 59, 59, 999);
const expectedParams = ({
shippedFrom,
scopeDays: params.scopeDays,
shippedTo
});
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');
2020-03-16 17:08:44 +00:00
});
});
});