salix/client/order/src/line/index.spec.js

95 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-08-07 14:04:42 +00:00
import './index.js';
describe('Order', () => {
describe('Component vnOrderLine', () => {
let $componentController;
let $state;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('order');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$state = {params: {id: 1}};
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnOrderLine', {$state: $state});
controller.rows = [{id: 1}];
controller.$scope.popover = {relocate: () => {}};
controller.$scope.descriptor = {show: () => {}};
controller.vnApp = {showSuccess: () => {}};
}));
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();
});
});
describe('removeRow()', () => {
it('should remove a row from rows and add his id to idsRemoved', () => {
controller.removeRow(0);
expect(controller.rows.length).toBe(0);
expect(controller.idsToRemove[0]).toBe(1);
});
});
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();
});
});
describe('save()', () => {
it('should make a query to remove the selected rows and call vnApp.showSuccess', () => {
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`/order/api/OrderRows/removes`).respond();
controller.save();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
});
});