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

72 lines
2.2 KiB
JavaScript

describe('Component vnCalendar', () => {
let controller;
let $element;
let date = new Date();
date.setHours(0, 0, 0, 0);
date.setDate(1);
beforeEach(ngModule('vnCore'));
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`, () => {
jest.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`, () => {
jest.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`, () => {
jest.spyOn(controller, 'emit');
const day = new Date();
day.setHours(0, 0, 0, 0);
const clickEvent = new Event('click');
const target = document.createElement('div');
target.dispatchEvent(clickEvent);
controller.select(clickEvent, day);
let res = {
$event: clickEvent,
$days: [day],
$type: 'day'
};
expect(controller.field).toEqual(day);
expect(controller.emit).toHaveBeenCalledWith('selection', res);
});
});
});