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

72 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-04-03 10:39:24 +00:00
describe('Component vnCalendar', () => {
let controller;
let $element;
2023-01-16 14:18:24 +00:00
let date = Date.vnNew();
2019-10-23 15:38:35 +00:00
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');
2019-10-23 15:38:35 +00:00
controller.defaultDate = date;
}));
afterEach(() => {
$element.remove();
});
describe('moveNext()', () => {
2019-10-23 15:38:35 +00:00
it(`should shift to the next month, then emit a 'move' event`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2019-10-23 15:38:35 +00:00
let nextMonth = new Date(date.getTime());
nextMonth.setMonth(nextMonth.getMonth() + 1);
2019-10-23 15:38:35 +00:00
controller.moveNext();
2019-10-23 15:38:35 +00:00
expect(controller.month).toEqual(nextMonth.getMonth());
expect(controller.emit).toHaveBeenCalledWith('move', {$date: nextMonth});
});
});
describe('movePrevious()', () => {
2019-10-23 15:38:35 +00:00
it(`should shift to the previous month, then emit a 'move' event`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2019-10-23 15:38:35 +00:00
let previousMonth = new Date(date.getTime());
previousMonth.setMonth(previousMonth.getMonth() - 1);
2019-10-23 15:38:35 +00:00
controller.movePrevious();
2019-10-23 15:38:35 +00:00
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`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2019-10-23 15:38:35 +00:00
2023-01-16 14:18:24 +00:00
const day = Date.vnNew();
2019-10-23 15:38:35 +00:00
day.setHours(0, 0, 0, 0);
2020-02-26 10:05:29 +00:00
const clickEvent = new Event('click');
const target = document.createElement('div');
target.dispatchEvent(clickEvent);
controller.select(clickEvent, day);
let res = {
2020-02-26 10:05:29 +00:00
$event: clickEvent,
2019-10-23 15:38:35 +00:00
$days: [day],
$type: 'day'
};
2019-10-23 15:38:35 +00:00
expect(controller.field).toEqual(day);
expect(controller.emit).toHaveBeenCalledWith('selection', res);
});
});
});