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

88 lines
2.8 KiB
JavaScript

describe('Component vnCalendar', () => {
let controller;
let $element;
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 = new Date();
}));
afterEach(() => {
$element.remove();
});
describe('data() setter', () => {
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();
controller.data = [
{dated: currentDate, name: 'Event 1'},
{dated: currentDate, name: 'Event 2'},
];
expect(controller.events[0].dated instanceof Object).toBeTruthy();
expect(controller.repaint).toHaveBeenCalledWith();
});
});
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 dated = new Date();
const days = [{dated}];
controller.days = days;
controller.select(0);
let res = {
$days: [dated],
$type: 'day'
};
expect(controller.emit).toHaveBeenCalledWith('selection', res);
});
});
describe('renderStyle()', () => {
it(`should normalize CSS attributes`, () => {
const result = controller.renderStyle({
backgroundColor: 'red'
});
expect(result['background-color']).toEqual('red');
});
});
});