salix/modules/order/front/line/index.spec.js

87 lines
3.3 KiB
JavaScript

import './index.js';
xdescribe('Order', () => {
describe('Component vnOrderLine', () => {
let $state;
let controller;
let $httpBackend;
beforeEach(ngModule('order'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$state = {params: {id: 1}};
$httpBackend = _$httpBackend_;
controller = $componentController('vnOrderLine', {$state});
controller.rows = [{id: 1}];
controller.$scope.popover = {relocate: () => {}};
controller.$scope.descriptor = {show: () => {}};
controller.vnApp = {showSuccess: () => {}};
controller.card = {reload: () => {}};
}));
describe('getRows()', () => {
it('should make a query to get the rows of a given order', () => {
let filter = {
where: {orderFk: controller.$state.params.id},
include: [{
relation: 'item'
},
{relation: 'warehouse'}]
};
filter = encodeURIComponent(JSON.stringify(filter));
$httpBackend.expectGET(`/order/api/OrderRows?filter=${filter}`).respond({data: [{id: 1}]});
controller.getRows();
$httpBackend.flush();
});
});
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}});
controller.getVAT();
$httpBackend.flush();
});
});
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();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.rows.length).toBe(0);
expect(controller.idsToRemove).toBe(undefined);
});
});
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();
});
});
});
});