2018-08-07 14:04:42 +00:00
|
|
|
import './index.js';
|
|
|
|
|
2019-01-14 14:04:30 +00:00
|
|
|
xdescribe('Order', () => {
|
2018-08-07 14:04:42 +00:00
|
|
|
describe('Component vnOrderLine', () => {
|
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2018-08-07 14:04:42 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
2018-08-07 14:04:42 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$state = {params: {id: 1}};
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnOrderLine', {$state});
|
2018-08-07 14:04:42 +00:00
|
|
|
controller.rows = [{id: 1}];
|
|
|
|
controller.$scope.popover = {relocate: () => {}};
|
|
|
|
controller.$scope.descriptor = {show: () => {}};
|
|
|
|
controller.vnApp = {showSuccess: () => {}};
|
2019-01-14 13:59:14 +00:00
|
|
|
controller.card = {reload: () => {}};
|
2018-08-07 14:04:42 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('getRows()', () => {
|
|
|
|
it('should make a query to get the rows of a given order', () => {
|
|
|
|
let filter = {
|
|
|
|
where: {orderFk: controller.$state.params.id},
|
|
|
|
include: [{
|
2018-11-06 09:49:38 +00:00
|
|
|
relation: 'item'
|
2018-08-07 14:04:42 +00:00
|
|
|
},
|
|
|
|
{relation: 'warehouse'}]
|
|
|
|
};
|
|
|
|
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
$httpBackend.expectGET(`/order/api/OrderRows?filter=${filter}`).respond({data: [{id: 1}]});
|
|
|
|
controller.getRows();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-08 13:21:06 +00:00
|
|
|
describe('getVAT()', () => {
|
|
|
|
it('should make a query to get the VAT of a given order', () => {
|
|
|
|
$httpBackend.expectGET(`/order/api/Orders/1/getVAT`).respond({data: {tax: 3}});
|
2018-08-07 14:04:42 +00:00
|
|
|
controller.getVAT();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-14 13:59:14 +00:00
|
|
|
describe('deleteRow()', () => {
|
|
|
|
it('should remove a row from rows and add save the data if the response is ACCEPT', () => {
|
|
|
|
expect(controller.rows.length).toBe(1);
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
spyOn(controller, 'getVAT');
|
|
|
|
controller.deleteRow('ACCEPT');
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`/order/api/OrderRows/removes`).respond();
|
|
|
|
$httpBackend.flush();
|
2018-08-07 14:04:42 +00:00
|
|
|
|
2019-01-14 13:59:14 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
2018-08-07 14:04:42 +00:00
|
|
|
expect(controller.rows.length).toBe(0);
|
2019-01-14 13:59:14 +00:00
|
|
|
expect(controller.idsToRemove).toBe(undefined);
|
2018-08-07 14:04:42 +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;
|
|
|
|
spyOn(controller.$scope.descriptor, 'show');
|
|
|
|
controller.showDescriptor(event, itemFk);
|
|
|
|
|
|
|
|
expect(controller.$scope.descriptor.itemFk).toBe(1);
|
|
|
|
expect(controller.$scope.descriptor.parent).toBe(1);
|
|
|
|
expect(controller.$scope.descriptor.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onDescriptorLoad()', () => {
|
|
|
|
it('should call $scope.popover.relocate()', () => {
|
|
|
|
spyOn(controller.$scope.popover, 'relocate');
|
|
|
|
controller.onDescriptorLoad();
|
|
|
|
|
|
|
|
expect(controller.$scope.popover.relocate).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|