salix/modules/worker/front/descriptor-popover/index.spec.js

108 lines
3.8 KiB
JavaScript

import './index.js';
describe('worker Component vnWorkerDescriptorPopover', () => {
let $httpBackend;
let $httpParamSerializer;
let $scope;
let controller;
let $element;
beforeEach(angular.mock.module('worker', $translateProvider => {
$translateProvider.translations('en', {});
}));
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!';
controller._workerFk = 1;
spyOn(controller, 'loadData');
controller.workerFk = 1;
expect(controller.worker).toEqual('I exist!');
expect(controller._workerFk).toEqual(1);
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`;
controller._workerFk = 1;
spyOn(controller, 'loadData');
controller.workerFk = 999;
expect(controller.worker).toBeNull();
expect(controller._workerFk).toEqual(999);
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`, () => {
controller.workerFk = 1;
controller.canceler = null;
let response = {};
let config = {
filter: {
where: {
id: controller.workerFk
},
include: [
{
relation: 'user',
scope: {
fields: ['name'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}, {
relation: 'client',
scope: {fields: ['fi']}
}, {
relation: 'sip',
scope: {fields: ['extension']}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
}
};
let json = $httpParamSerializer(config);
$httpBackend.whenGET(`api/Workers/findOne?${json}`).respond(response);
$httpBackend.expectGET(`api/Workers/findOne?${json}`);
controller.loadData();
$httpBackend.flush();
expect(controller.worker).toEqual(response);
});
});
});