2019-04-03 10:39:24 +00:00
|
|
|
describe('Component vnCalendar', () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
let controller;
|
|
|
|
let $element;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2019-04-03 09:34:58 +00:00
|
|
|
|
|
|
|
beforeEach(inject(($compile, $rootScope) => {
|
|
|
|
$element = $compile(`<vn-calendar></vn-calendar`)($rootScope);
|
|
|
|
controller = $element.controller('vnCalendar');
|
|
|
|
controller.defaultDate = new Date();
|
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
2019-04-03 10:39:24 +00:00
|
|
|
describe('data() setter', () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
it(`should set an array of events and convert string dates to string object, then call repaint() method`, () => {
|
|
|
|
spyOn(controller, 'repaint');
|
|
|
|
|
|
|
|
let currentDate = new Date().toString();
|
2019-04-03 10:39:24 +00:00
|
|
|
controller.data = [
|
2019-06-26 11:35:38 +00:00
|
|
|
{dated: currentDate, name: 'Event 1'},
|
|
|
|
{dated: currentDate, name: 'Event 2'},
|
2019-04-03 09:34:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller.events[0].dated instanceof Object).toBeTruthy();
|
|
|
|
expect(controller.repaint).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addEvent()', () => {
|
2019-04-03 10:39:24 +00:00
|
|
|
it(`should add an event to an array of events`, () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
controller.events = [];
|
|
|
|
controller.addEvent({
|
|
|
|
dated: new Date(),
|
2019-06-26 11:35:38 +00:00
|
|
|
name: 'My event'
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
const firstEvent = controller.events[0];
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(firstEvent.name).toEqual('My event');
|
2019-04-03 09:34:58 +00:00
|
|
|
expect(firstEvent.isRemovable).toBeDefined();
|
|
|
|
expect(firstEvent.isRemovable).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2019-04-03 10:39:24 +00:00
|
|
|
it(`should not repeat an event for the same date`, () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
const curDate = new Date();
|
2019-04-03 10:39:24 +00:00
|
|
|
curDate.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
controller.events = [{
|
2019-04-03 09:34:58 +00:00
|
|
|
dated: curDate,
|
2019-06-26 11:35:38 +00:00
|
|
|
name: 'My event 1'
|
2019-04-03 09:34:58 +00:00
|
|
|
}];
|
|
|
|
controller.addEvent({
|
|
|
|
dated: curDate,
|
2019-06-26 11:35:38 +00:00
|
|
|
name: 'My event 2'
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const firstEvent = controller.events[0];
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.events.length).toEqual(2);
|
|
|
|
expect(firstEvent.name).toEqual('My event 1');
|
2019-04-03 09:34:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeEvent()', () => {
|
2019-04-03 10:39:24 +00:00
|
|
|
it(`should remove an event from an array of events`, () => {
|
2019-04-03 09:34:58 +00:00
|
|
|
const curDate = new Date();
|
|
|
|
controller._events = [{
|
|
|
|
dated: curDate,
|
2019-06-26 11:35:38 +00:00
|
|
|
name: 'My event 1',
|
2019-04-03 09:34:58 +00:00
|
|
|
className: 'color'
|
|
|
|
}];
|
|
|
|
controller.removeEvent(curDate);
|
|
|
|
|
|
|
|
expect(controller.events.length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moveNext()', () => {
|
|
|
|
it(`should shift to the next n months, then emit a 'moveNext' event`, () => {
|
|
|
|
spyOn(controller, 'emit');
|
|
|
|
const currentMonth = controller.defaultDate.getMonth();
|
|
|
|
let nextMonth = currentMonth + 1;
|
|
|
|
|
|
|
|
controller.moveNext(1);
|
|
|
|
|
|
|
|
expect(controller.defaultDate.getMonth()).toEqual(nextMonth);
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('moveNext');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('movePrevious()', () => {
|
|
|
|
it(`should shift to the previous n months, then emit a 'movePrevious' event`, () => {
|
|
|
|
spyOn(controller, 'emit');
|
|
|
|
const currentMonth = controller.defaultDate.getMonth();
|
|
|
|
let previousMonth = currentMonth - 1;
|
|
|
|
|
|
|
|
controller.movePrevious(1);
|
|
|
|
|
|
|
|
expect(controller.defaultDate.getMonth()).toEqual(previousMonth);
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('movePrevious');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('select()', () => {
|
|
|
|
it(`should return the selected element, then emit a 'selection' event`, () => {
|
|
|
|
spyOn(controller, 'emit');
|
|
|
|
const days = [{dated: new Date()}];
|
|
|
|
controller.days = days;
|
|
|
|
|
|
|
|
controller.select(0);
|
|
|
|
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('selection', {values: days});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|