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

57 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-11-16 18:04:37 +00:00
import './index.js';
describe('Travel Component vnTravelDescriptorMenu', () => {
let controller;
2020-12-28 13:53:26 +00:00
let $httpBackend;
2020-11-16 18:04:37 +00:00
beforeEach(ngModule('travel'));
2020-12-28 13:53:26 +00:00
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
2020-11-16 18:04:37 +00:00
const $element = angular.element('<vn-travel-descriptor-menu></vn-travel-descriptor-menu>');
controller = $componentController('vnTravelDescriptorMenu', {$element});
2020-12-28 13:53:26 +00:00
controller._travelId = 5;
2020-11-16 18:04:37 +00:00
}));
describe('onCloneAccept()', () => {
it('should call state.go with the travel data', () => {
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
controller.travel = {
ref: 'the ref',
agencyFk: 'the agency',
shipped: 'the shipped date',
landed: 'the landing date',
warehouseInFk: 'the receiver warehouse',
warehouseOutFk: 'the sender warehouse'
};
controller.onCloneAccept();
const params = JSON.stringify({
ref: controller.travel.ref,
agencyModeFk: controller.travel.agencyFk,
shipped: controller.travel.shipped,
landed: controller.travel.landed,
warehouseInFk: controller.travel.warehouseInFk,
warehouseOutFk: controller.travel.warehouseOutFk
});
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {'q': params});
});
});
2020-12-28 13:53:26 +00:00
describe('onCloneWithEntriesAccept()', () => {
it('should make an HTTP query and then call to the $state.go method with the returned id', () => {
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
$httpBackend.expect('POST', `Travels/${controller.travelId}/cloneWithEntries`).respond(200, 9);
controller.onCloneWithEntriesAccept();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('travel.card.basicData', {
id: jasmine.any(Number)
});
});
});
2020-11-16 18:04:37 +00:00
});