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