salix/modules/worker/front/calendar/index.spec.js

118 lines
4.4 KiB
JavaScript

import './index';
describe('Worker', () => {
describe('Component vnWorkerCalendar', () => {
let $componentController;
let $httpParamSerializer;
let $httpBackend;
let $scope;
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnWorkerCalendar', {$scope, $httpBackend});
}));
describe('started() getter', () => {
it(`should return first day and month of current year`, () => {
let started = new Date();
started.setHours(0, 0, 0, 0);
started.setMonth(0);
started.setDate(1);
expect(controller.started).toEqual(started);
});
});
describe('ended() getter', () => {
it(`should return last day and month of current year`, () => {
const monthIndex = 11;
const ended = new Date();
ended.setHours(0, 0, 0, 0);
ended.setMonth(monthIndex + 1);
// Last day of previous month (January)
ended.setDate(0);
expect(controller.ended).toEqual(ended);
});
});
describe('monthsOfYear()', () => {
it(`should return an array of twelve months length`, () => {
const months = controller.monthsOfYear();
const ended = new Date();
ended.setHours(0, 0, 0, 0);
ended.setMonth(11);
ended.setDate(1);
expect(months.length).toEqual(12);
expect(months[0]).toEqual(controller.started);
expect(months[11]).toEqual(ended);
});
});
describe('worker() setter', () => {
it(`should perform a get query and call setHolidays() and setWorkerCalendar() methods`, () => {
const worker = {id: 106};
spyOn(controller, 'setHolidays');
spyOn(controller, 'setWorkerCalendar');
const expectedData = {
calendar: {},
absences: {}
};
let params = $httpParamSerializer({
workerFk: worker.id,
started: controller.started,
ended: controller.ended
});
$httpBackend.when('GET', `/worker/api/WorkerCalendars/absences?${params}`).respond(expectedData);
$httpBackend.expect('GET', `/worker/api/WorkerCalendars/absences?${params}`);
controller.worker = worker;
$httpBackend.flush();
expect(controller.setHolidays).toHaveBeenCalledWith(expectedData);
expect(controller.setHolidays).toHaveBeenCalledWith(expectedData);
});
});
describe('setHolidays()', () => {
it(`should `, () => {
const data = {holidays: [
{dated: new Date(), detail: {description: 'New year'}},
{dated: new Date(), detail: {description: 'Easter'}}
]};
controller.setHolidays(data);
expect(controller.events.length).toEqual(2);
expect(controller.events[0].title).toEqual('New year');
expect(controller.events[0].isRemovable).toEqual(false);
});
});
describe('setWorkerCalendar()', () => {
it(`should `, () => {
const data = {absences: [
{dated: new Date(), absenceType: {name: 'Holiday', rgb: '#000'}},
{dated: new Date(), absenceType: {name: 'Leave', rgb: '#000'}}
]};
controller.setWorkerCalendar(data);
expect(controller.events.length).toEqual(2);
expect(controller.events[0].title).toEqual('Holiday');
expect(controller.events[0].style).toBeDefined();
expect(controller.events[1].title).toEqual('Leave');
expect(controller.events[1].style).toBeDefined();
});
});
});
});