2019-03-22 11:51:44 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Worker', () => {
|
|
|
|
describe('Component vnWorkerCalendar', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('worker', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2019-03-22 11:51:44 +00:00
|
|
|
|
|
|
|
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()', () => {
|
2019-05-10 11:16:37 +00:00
|
|
|
it(`should set holidays`, () => {
|
2019-03-22 11:51:44 +00:00
|
|
|
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);
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.events[0].name).toEqual('New year');
|
2019-03-22 11:51:44 +00:00
|
|
|
expect(controller.events[0].isRemovable).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setWorkerCalendar()', () => {
|
2019-05-10 11:16:37 +00:00
|
|
|
it(`should set absences of differente types`, () => {
|
2019-03-22 11:51:44 +00:00
|
|
|
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);
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.events[0].name).toEqual('Holiday');
|
2019-03-22 11:51:44 +00:00
|
|
|
expect(controller.events[0].style).toBeDefined();
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.events[1].name).toEqual('Leave');
|
2019-03-22 11:51:44 +00:00
|
|
|
expect(controller.events[1].style).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2019-05-10 11:16:37 +00:00
|
|
|
|
|
|
|
describe('absenceTypes() setter', () => {
|
|
|
|
it(`should set the absence types in the controller`, () => {
|
|
|
|
const absenceTypes = [
|
|
|
|
{id: 1, name: 'Holiday', rgb: '#000'},
|
|
|
|
{id: 2, name: 'Leave', rgb: '#000'}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller._absenceTypes).not.toBeDefined();
|
|
|
|
|
|
|
|
controller.absenceTypes = absenceTypes;
|
|
|
|
|
|
|
|
expect(controller._absenceTypes.length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set the absence types in the controller as formated legends`, () => {
|
|
|
|
const absenceTypes = [
|
|
|
|
{id: 1, name: 'Holiday', rgb: '#000'},
|
|
|
|
{id: 2, name: 'Leave', rgb: '#000'}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller.legends).not.toBeDefined();
|
|
|
|
|
|
|
|
controller.absenceTypes = absenceTypes;
|
|
|
|
|
|
|
|
expect(controller.legends.length).toEqual(2);
|
|
|
|
expect(controller.legends[0].color).toBeDefined();
|
|
|
|
expect(controller.legends[1].color).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2019-03-22 11:51:44 +00:00
|
|
|
});
|
|
|
|
});
|