2018-08-07 15:07:41 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Order', () => {
|
|
|
|
describe('Component vnOrderVolume', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let $scope;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2018-08-07 15:07:41 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
|
2018-08-07 15:07:41 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.model = {data: [{itemFk: 1}, {itemFk: 2}], accept: () => {
|
|
|
|
return {
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
$scope.descriptor = {show: () => {}};
|
|
|
|
$scope.popover = {relocate: () => {}};
|
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = 1;
|
2020-03-17 14:18:02 +00:00
|
|
|
const $element = angular.element('<vn-order-volume></vn-order-volume>');
|
|
|
|
controller = $componentController('vnOrderVolume', {$element, $scope});
|
2018-08-07 15:07:41 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should join the sale volumes to its respective sale', () => {
|
|
|
|
let response = {volumes: [{itemFk: 1, volume: 0.008}, {itemFk: 2, volume: 0.003}]};
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET(`Orders/1/getVolumes`).respond(response);
|
|
|
|
$httpBackend.expectGET(`Orders/1/getVolumes`);
|
2018-08-07 15:07:41 +00:00
|
|
|
controller.onDataChange();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-03-17 14:18:02 +00:00
|
|
|
expect(controller.$.model.data[0].volume).toBe(0.008);
|
|
|
|
expect(controller.$.model.data[1].volume).toBe(0.003);
|
2018-08-07 15:07:41 +00:00
|
|
|
});
|
2019-09-13 14:09:14 +00:00
|
|
|
|
2018-08-07 15:07:41 +00:00
|
|
|
describe('showDescriptor()', () => {
|
|
|
|
it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => {
|
|
|
|
let event = {target: 1};
|
|
|
|
let itemFk = 1;
|
2020-03-17 14:18:02 +00:00
|
|
|
jest.spyOn(controller.$.descriptor, 'show');
|
2018-08-07 15:07:41 +00:00
|
|
|
controller.showDescriptor(event, itemFk);
|
|
|
|
|
2020-03-17 14:18:02 +00:00
|
|
|
expect(controller.$.descriptor.itemFk).toBe(1);
|
|
|
|
expect(controller.$.descriptor.parent).toBe(1);
|
|
|
|
expect(controller.$.descriptor.show).toHaveBeenCalledWith();
|
2018-08-07 15:07:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onDescriptorLoad()', () => {
|
|
|
|
it('should call $scope.popover.relocate()', () => {
|
2020-03-17 14:18:02 +00:00
|
|
|
jest.spyOn(controller.$.popover, 'relocate');
|
2018-08-07 15:07:41 +00:00
|
|
|
controller.onDescriptorLoad();
|
|
|
|
|
2020-03-17 14:18:02 +00:00
|
|
|
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
|
2018-08-07 15:07:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|