99 lines
3.5 KiB
JavaScript
99 lines
3.5 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Worker', () => {
|
|
describe('Component vnWorkerTimeControl', () => {
|
|
let $scope;
|
|
let controller;
|
|
let $element;
|
|
|
|
beforeEach(angular.mock.module('worker', $translateProvider => {
|
|
$translateProvider.translations('en', {});
|
|
}));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
|
$scope = $rootScope.$new();
|
|
$element = angular.element('<vn-worker-time-control></vn-worker-time-control>');
|
|
controller = $componentController('vnWorkerTimeControl', {$scope, $element});
|
|
}));
|
|
|
|
describe('worker() setter', () => {
|
|
it(`should set worker data and then call getHours() method`, () => {
|
|
spyOn(controller, 'getHours');
|
|
controller.worker = {id: 106};
|
|
$scope.$apply();
|
|
|
|
expect(controller.getHours).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('hours() setter', () => {
|
|
it(`should set hours data and then call build() method`, () => {
|
|
spyOn(controller, 'build');
|
|
controller.hours = [{id: 1}, {id: 2}];
|
|
$scope.$apply();
|
|
|
|
expect(controller.build).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('getWeekdayTotalHours() ', () => {
|
|
it(`should return a total worked hours from 07:00 to 15:00`, () => {
|
|
const hourOne = new Date();
|
|
hourOne.setHours(7, 0, 0, 0);
|
|
const hourTwo = new Date();
|
|
hourTwo.setHours(10, 0, 0, 0);
|
|
const hourThree = new Date();
|
|
hourThree.setHours(10, 20, 0, 0);
|
|
const hourFour = new Date();
|
|
hourFour.setHours(15, 0, 0, 0);
|
|
|
|
const weekday = {hours: [
|
|
{id: 1, timed: hourOne},
|
|
{id: 2, timed: hourTwo},
|
|
{id: 3, timed: hourThree},
|
|
{id: 4, timed: hourFour}
|
|
]};
|
|
|
|
const result = controller.getWeekdayTotalHours(weekday);
|
|
|
|
expect(result).toEqual('08:00');
|
|
});
|
|
});
|
|
|
|
describe('weekTotalHours() ', () => {
|
|
it(`should return a total worked hours from a week`, () => {
|
|
const hourOne = new Date();
|
|
hourOne.setHours(7, 0, 0, 0);
|
|
const hourTwo = new Date();
|
|
hourTwo.setHours(10, 0, 0, 0);
|
|
const hourThree = new Date();
|
|
hourThree.setHours(10, 20, 0, 0);
|
|
const hourFour = new Date();
|
|
hourFour.setHours(15, 0, 0, 0);
|
|
|
|
const weekday = {hours: [
|
|
{id: 1, timed: hourOne},
|
|
{id: 2, timed: hourTwo},
|
|
{id: 3, timed: hourThree},
|
|
{id: 4, timed: hourFour}
|
|
]};
|
|
controller.weekDays = [weekday];
|
|
|
|
const weekdayHours = controller.getWeekdayTotalHours(weekday);
|
|
const weekHours = controller.weekTotalHours;
|
|
|
|
expect(weekdayHours).toEqual('08:00');
|
|
expect(weekHours).toEqual('08:00');
|
|
});
|
|
});
|
|
|
|
describe('formatHours() ', () => {
|
|
it(`should format a passed timestamp to hours and minutes`, () => {
|
|
const result = controller.formatHours(3600000);
|
|
|
|
expect(result).toEqual('01:00');
|
|
});
|
|
});
|
|
});
|
|
});
|