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

93 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-08-07 14:04:42 +00:00
import './index.js';
2019-04-05 05:52:08 +00:00
import watcher from 'core/mocks/watcher';
2018-08-07 14:04:42 +00:00
2019-04-05 05:52:08 +00:00
describe('Order', () => {
2018-08-07 14:04:42 +00:00
describe('Component vnOrderLine', () => {
let $state;
let controller;
let $httpBackend;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('order', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-08-07 14:04:42 +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_;
controller = $componentController('vnOrderLine', {$state});
2018-08-07 14:04:42 +00:00
controller.rows = [{id: 1}];
2019-04-05 05:52:08 +00:00
controller.$scope.watcher = watcher;
2018-08-07 14:04:42 +00:00
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();
});
});
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');
2019-04-05 05:52:08 +00:00
spyOn(controller.card, 'reload');
2019-01-14 13:59:14 +00:00
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!');
2019-04-05 05:52:08 +00:00
expect(controller.card.reload).toHaveBeenCalledWith();
2018-08-07 14:04:42 +00:00
expect(controller.rows.length).toBe(0);
2019-04-05 05:52:08 +00:00
expect(controller.lineIdToRemove).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();
});
});
});
});