2019-04-03 10:39:24 +00:00
|
|
|
describe('Component vnCalendar', () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2019-04-03 09:34:58 +00:00
|
|
|
|
|
|
|
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;
|
2019-04-03 09:34:58 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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-04-03 09:34:58 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
controller.moveNext();
|
2019-04-03 09:34:58 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
expect(controller.month).toEqual(nextMonth.getMonth());
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('move', {$date: nextMonth});
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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-04-03 09:34:58 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
controller.movePrevious();
|
2019-04-03 09:34:58 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
expect(controller.month).toEqual(previousMonth.getMonth());
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('move', {$date: previousMonth});
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2019-04-03 09:34:58 +00:00
|
|
|
|
2019-10-01 11:45:43 +00:00
|
|
|
let res = {
|
2020-02-26 10:05:29 +00:00
|
|
|
$event: clickEvent,
|
2019-10-23 15:38:35 +00:00
|
|
|
$days: [day],
|
2019-10-01 11:45:43 +00:00
|
|
|
$type: 'day'
|
|
|
|
};
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
expect(controller.field).toEqual(day);
|
2019-10-01 11:45:43 +00:00
|
|
|
expect(controller.emit).toHaveBeenCalledWith('selection', res);
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|