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

101 lines
3.4 KiB
JavaScript

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('travelId()', () => {
it(`should not apply any changes if the received id is the same stored in _travelId`, () => {
controller.travel = 'I exist!';
controller._travelId = 1;
jest.spyOn(controller, 'loadData');
controller.travelId = 1;
expect(controller.travel).toEqual('I exist!');
expect(controller._travelId).toEqual(1);
expect(controller.loadData).not.toHaveBeenCalled();
});
it(`should set the received id into _travelId, set the travel to null and then call loadData()`, () => {
controller.travel = `Please don't`;
controller._travelId = 1;
jest.spyOn(controller, 'loadData');
controller.travelId = 999;
expect(controller.travel).toBeNull();
expect(controller._travelId).toEqual(999);
expect(controller.loadData).toHaveBeenCalledWith();
});
});
describe('show()', () => {
it(`should call the show()`, () => {
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`, () => {
controller.travelId = 1;
controller.canceler = null;
let response = {};
let config = {
filter: {
fields: [
'id',
'ref',
'shipped',
'landed',
'totalEntries',
'warehouseInFk',
'warehouseOutFk'
],
where: {
id: controller.travelId
},
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);
});
});
});