2019-02-15 11:39:21 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('worker Component vnWorkerDescriptorPopover', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $element;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('worker', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2019-02-15 11:39:21 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
|
|
$element = angular.element(`<div></div>`);
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.popover = {relocate: () => {}, show: () => {}};
|
|
|
|
controller = $componentController('vnWorkerDescriptorPopover', {$scope, $element});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('workerFk()', () => {
|
|
|
|
it(`should not apply any changes if the received id is the same stored in _workerFk`, () => {
|
|
|
|
controller.worker = 'I exist!';
|
2019-04-25 06:28:23 +00:00
|
|
|
controller._workerFk = 1;
|
2019-02-15 11:39:21 +00:00
|
|
|
spyOn(controller, 'loadData');
|
2019-04-25 06:28:23 +00:00
|
|
|
controller.workerFk = 1;
|
2019-02-15 11:39:21 +00:00
|
|
|
|
|
|
|
expect(controller.worker).toEqual('I exist!');
|
2019-04-25 06:28:23 +00:00
|
|
|
expect(controller._workerFk).toEqual(1);
|
2019-02-15 11:39:21 +00:00
|
|
|
expect(controller.loadData).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => {
|
|
|
|
controller.worker = `Please don't`;
|
2019-04-25 06:28:23 +00:00
|
|
|
controller._workerFk = 1;
|
2019-02-15 11:39:21 +00:00
|
|
|
spyOn(controller, 'loadData');
|
2019-04-25 06:28:23 +00:00
|
|
|
controller.workerFk = 999;
|
2019-02-15 11:39:21 +00:00
|
|
|
|
|
|
|
expect(controller.worker).toBeNull();
|
2019-04-25 06:28:23 +00:00
|
|
|
expect(controller._workerFk).toEqual(999);
|
2019-02-15 11:39:21 +00:00
|
|
|
expect(controller.loadData).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('show()', () => {
|
|
|
|
it(`should call the show()`, () => {
|
|
|
|
spyOn(controller.$.popover, 'show');
|
|
|
|
controller.show();
|
|
|
|
|
|
|
|
expect(controller.$.popover.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loadData()', () => {
|
|
|
|
it(`should perform a get query to store the worker data into the controller`, () => {
|
2019-04-25 06:28:23 +00:00
|
|
|
controller.workerFk = 1;
|
2019-02-15 11:39:21 +00:00
|
|
|
controller.canceler = null;
|
|
|
|
let response = {};
|
|
|
|
|
|
|
|
let config = {
|
|
|
|
filter: {
|
2019-02-19 14:09:50 +00:00
|
|
|
where: {
|
2019-04-25 06:28:23 +00:00
|
|
|
id: controller.workerFk
|
2019-02-19 14:09:50 +00:00
|
|
|
},
|
2019-02-15 11:39:21 +00:00
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'user',
|
2019-03-15 11:58:26 +00:00
|
|
|
scope: {
|
|
|
|
fields: ['name'],
|
|
|
|
include: {
|
|
|
|
relation: 'emailUser',
|
|
|
|
scope: {
|
|
|
|
fields: ['email']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 11:39:21 +00:00
|
|
|
}, {
|
|
|
|
relation: 'client',
|
|
|
|
scope: {fields: ['fi']}
|
|
|
|
}, {
|
|
|
|
relation: 'sip',
|
|
|
|
scope: {fields: ['extension']}
|
2019-02-19 14:09:50 +00:00
|
|
|
}, {
|
|
|
|
relation: 'department',
|
|
|
|
scope: {
|
|
|
|
include: {
|
|
|
|
relation: 'department'
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 11:39:21 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let json = $httpParamSerializer(config);
|
|
|
|
|
2019-02-19 14:09:50 +00:00
|
|
|
$httpBackend.whenGET(`api/Workers/findOne?${json}`).respond(response);
|
|
|
|
$httpBackend.expectGET(`api/Workers/findOne?${json}`);
|
2019-02-15 11:39:21 +00:00
|
|
|
controller.loadData();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.worker).toEqual(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|