2019-05-17 11:27:51 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Worker', () => {
|
|
|
|
describe('Component vnWorkerTimeControl', () => {
|
2019-10-23 15:38:35 +00:00
|
|
|
let $httpBackend;
|
2019-05-17 11:27:51 +00:00
|
|
|
let $scope;
|
2019-05-21 10:56:29 +00:00
|
|
|
let $element;
|
2019-10-23 15:38:35 +00:00
|
|
|
let controller;
|
2019-05-17 11:27:51 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('worker'));
|
2019-05-17 11:27:51 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
beforeEach(angular.mock.inject(($compile, $rootScope, $stateParams, _$httpBackend_) => {
|
|
|
|
$stateParams.id = 1;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2019-05-17 11:27:51 +00:00
|
|
|
$scope = $rootScope.$new();
|
2019-10-23 15:38:35 +00:00
|
|
|
$element = $compile('<vn-worker-time-control></vn-worker-time-control>')($scope);
|
|
|
|
controller = $element.controller('vnWorkerTimeControl');
|
2019-05-17 11:27:51 +00:00
|
|
|
}));
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$scope.$destroy();
|
|
|
|
$element.remove();
|
2019-05-17 11:27:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('hours() setter', () => {
|
2019-10-23 15:38:35 +00:00
|
|
|
it(`should set hours data at it's corresponding week day`, () => {
|
|
|
|
let wednesday = new Date(controller.started.getTime());
|
|
|
|
wednesday.setDate(wednesday.getDate() + 2);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'WorkerTimeControls/filter')
|
2019-10-23 15:38:35 +00:00
|
|
|
.respond([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
timed: controller.started.toJSON(),
|
|
|
|
userFk: 1
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
timed: wednesday.toJSON(),
|
|
|
|
userFk: 1
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
timed: wednesday.toJSON(),
|
|
|
|
userFk: 1
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.weekDays.length).toEqual(7);
|
|
|
|
expect(controller.weekDays[0].hours.length).toEqual(1);
|
|
|
|
expect(controller.weekDays[2].hours.length).toEqual(2);
|
2019-05-17 11:27:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|