salix/front/core/components/calendar/index.spec.js

68 lines
2.0 KiB
JavaScript

describe('Component vnCalendar', () => {
let controller;
let $element;
let date = new Date();
date.setHours(0, 0, 0, 0);
date.setDate(1);
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-calendar></vn-calendar`)($rootScope);
controller = $element.controller('vnCalendar');
controller.defaultDate = date;
}));
afterEach(() => {
$element.remove();
});
describe('moveNext()', () => {
it(`should shift to the next month, then emit a 'move' event`, () => {
spyOn(controller, 'emit');
let nextMonth = new Date(date.getTime());
nextMonth.setMonth(nextMonth.getMonth() + 1);
controller.moveNext();
expect(controller.month).toEqual(nextMonth.getMonth());
expect(controller.emit).toHaveBeenCalledWith('move', {$date: nextMonth});
});
});
describe('movePrevious()', () => {
it(`should shift to the previous month, then emit a 'move' event`, () => {
spyOn(controller, 'emit');
let previousMonth = new Date(date.getTime());
previousMonth.setMonth(previousMonth.getMonth() - 1);
controller.movePrevious();
expect(controller.month).toEqual(previousMonth.getMonth());
expect(controller.emit).toHaveBeenCalledWith('move', {$date: previousMonth});
});
});
describe('select()', () => {
it(`should return the selected element, then emit a 'selection' event`, () => {
spyOn(controller, 'emit');
const day = new Date();
day.setHours(0, 0, 0, 0);
controller.select(day);
let res = {
$days: [day],
$type: 'day'
};
expect(controller.field).toEqual(day);
expect(controller.emit).toHaveBeenCalledWith('selection', res);
});
});
});