import './index'; describe('Worker', () => { describe('Component vnWorkerCalendar', () => { let $httpBackend; let $scope; let $element; let controller; let year = new Date().getFullYear(); beforeEach(ngModule('worker')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $element = angular.element('
'); controller = $componentController('vnWorkerCalendar', {$element, $scope}); })); afterEach(() => { $element.remove(); $scope.$destroy(); }); describe('started property', () => { it(`should return first day and month of current year`, () => { let started = new Date(year, 0, 1); expect(controller.started).toEqual(started); }); }); describe('ended property', () => { it(`should return last day and month of current year`, () => { let ended = new Date(year, 11, 31); expect(controller.ended).toEqual(ended); }); }); describe('months property', () => { it(`should return an array of twelve months length`, () => { const ended = new Date(year, 11, 1); expect(controller.months.length).toEqual(12); expect(controller.months[0]).toEqual(controller.started); expect(controller.months[11]).toEqual(ended); }); }); describe('worker() setter', () => { it(`should perform a get query and set the reponse data on the model`, () => { let today = new Date(); let tomorrow = new Date(today.getTime()); tomorrow.setDate(tomorrow.getDate() + 1); let yesterday = new Date(today.getTime()); yesterday.setDate(yesterday.getDate() - 1); $httpBackend.whenRoute('GET', 'WorkerCalendars/absences') .respond({ holidays: [ {dated: today, detail: {description: 'New year'}}, {dated: tomorrow, detail: {description: 'Easter'}} ], absences: [ {dated: today, absenceType: {name: 'Holiday', rgb: '#aaa'}}, {dated: yesterday, absenceType: {name: 'Leave', rgb: '#bbb'}} ] }); controller.worker = {id: 1}; $httpBackend.flush(); let events = controller.events; expect(events[today.getTime()].name).toEqual('Holiday'); expect(events[tomorrow.getTime()].name).toEqual('Easter'); expect(events[yesterday.getTime()].name).toEqual('Leave'); expect(events[yesterday.getTime()].color).toEqual('#bbb'); }); }); describe('formatDay()', () => { it(`should set the day element style`, () => { let today = new Date(); $httpBackend.whenRoute('GET', 'WorkerCalendars/absences') .respond({ absences: [ {dated: today, absenceType: {name: 'Holiday', rgb: '#000'}} ] }); controller.worker = {id: 1}; $httpBackend.flush(); let dayElement = angular.element('