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

105 lines
3.7 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('worker Component vnWorkerDescriptorPopover', () => {
let $httpBackend;
let $httpParamSerializer;
let $scope;
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$scope = $rootScope.$new();
$scope.popover = {relocate: () => {}, show: () => {}};
2020-03-18 11:55:22 +00:00
const $element = angular.element(`<vn-worker-descriptor-popover></vn-worker-descriptor-popover>`);
controller = $componentController('vnWorkerDescriptorPopover', {$element, $scope});
}));
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;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'loadData');
2019-04-25 06:28:23 +00:00
controller.workerFk = 1;
expect(controller.worker).toEqual('I exist!');
2019-04-25 06:28:23 +00:00
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`;
2019-04-25 06:28:23 +00:00
controller._workerFk = 1;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'loadData');
2019-04-25 06:28:23 +00:00
controller.workerFk = 999;
expect(controller.worker).toBeNull();
2019-04-25 06:28:23 +00:00
expect(controller._workerFk).toEqual(999);
expect(controller.loadData).toHaveBeenCalledWith();
});
});
describe('show()', () => {
it(`should call the show()`, () => {
2020-02-26 12:22:52 +00:00
jest.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;
controller.canceler = null;
let response = {};
let config = {
filter: {
where: {
2019-04-25 06:28:23 +00:00
id: controller.workerFk
},
include: [
{
relation: 'user',
2019-03-15 11:58:26 +00:00
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(`Workers/findOne?${json}`).respond(response);
$httpBackend.expectGET(`Workers/findOne?${json}`);
controller.loadData();
$httpBackend.flush();
expect(controller.worker).toEqual(response);
});
});
});