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

101 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-02-18 09:33:17 +00:00
import './index.js';
describe('travel Component vnTravelDescriptorPopover', () => {
let $httpBackend;
let $httpParamSerializer;
let $scope;
let controller;
let $element;
beforeEach(ngModule('travel'));
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('vnTravelDescriptorPopover', {$scope, $element});
}));
describe('travelFk()', () => {
it(`should not apply any changes if the received id is the same stored in _travelFk`, () => {
controller.travel = 'I exist!';
controller._travelFk = 1;
spyOn(controller, 'loadData');
controller.travelFk = 1;
expect(controller.travel).toEqual('I exist!');
expect(controller._travelFk).toEqual(1);
expect(controller.loadData).not.toHaveBeenCalled();
});
it(`should set the received id into _travelFk, set the travel to null and then call loadData()`, () => {
controller.travel = `Please don't`;
controller._travelFk = 1;
spyOn(controller, 'loadData');
controller.travelFk = 999;
expect(controller.travel).toBeNull();
expect(controller._travelFk).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.travelFk = 1;
controller.canceler = null;
let response = {};
let config = {
filter: {
fields: [
'id',
'ref',
'shipped',
'landed',
'totalEntries',
'warehouseInFk',
'warehouseOutFk'
],
where: {
id: controller.travelFk
},
include: [
{
relation: 'warehouseIn',
scope: {
fields: ['name']
}
}, {
relation: 'warehouseOut',
scope: {
fields: ['name']
}
}
]
}
};
let json = $httpParamSerializer(config);
$httpBackend.whenGET(`Travels/findOne?${json}`).respond(response);
$httpBackend.expectGET(`Travels/findOne?${json}`);
controller.loadData();
$httpBackend.flush();
expect(controller.travel).toEqual(response);
});
});
});