salix/modules/item/front/item-shelving/index.spec.js

82 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2022-10-05 13:13:48 +00:00
import './index';
import crudModel from 'core/mocks/crud-model';
2022-10-11 07:13:29 +00:00
describe('item shelving', () => {
describe('Component vnItemShelving', () => {
2022-10-05 13:13:48 +00:00
let controller;
let $httpBackend;
2022-10-11 07:13:29 +00:00
beforeEach(ngModule('item'));
2022-10-05 13:13:48 +00:00
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
2022-10-11 07:13:29 +00:00
const $element = angular.element('<vn-item-shelving></vn-item-shelving>');
controller = $componentController('vnItemShelving', {$element});
2022-10-05 13:13:48 +00:00
controller.$.model = crudModel;
controller.$.model.data = [
2022-10-11 07:13:29 +00:00
{itemShelvingFk: 1, packing: 10, stock: 1},
{itemShelvingFk: 2, packing: 12, stock: 5},
{itemShelvingFk: 4, packing: 20, stock: 10}
2022-10-05 13:13:48 +00:00
];
2022-10-11 07:13:29 +00:00
const modelData = controller.$.model.data;
modelData[0].checked = true;
modelData[1].checked = true;
2022-10-05 13:13:48 +00:00
}));
describe('checked() getter', () => {
2022-10-11 07:13:29 +00:00
it('should return a the selected rows', () => {
const result = controller.checked;
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(result).toEqual(expect.arrayContaining([1, 2]));
2022-10-05 13:13:48 +00:00
});
});
2022-10-11 07:13:29 +00:00
describe('calculateTotals()', () => {
it('should calculate the total of labels', () => {
controller.calculateTotals();
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(controller.labelTotal).toEqual(1.0166666666666666);
2022-10-05 13:13:48 +00:00
});
});
2022-10-11 07:13:29 +00:00
describe('onRemove()', () => {
it('shoud remove the selected lines', () => {
jest.spyOn(controller.$.model, 'refresh');
const expectedParams = {itemShelvingIds: [1, 2]};
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
$httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200);
controller.onRemove();
2022-10-05 13:13:48 +00:00
$httpBackend.flush();
2022-10-11 07:13:29 +00:00
expect(controller.$.model.refresh).toHaveBeenCalled();
2022-10-05 13:13:48 +00:00
});
});
describe('exprBuilder()', () => {
2022-10-11 07:13:29 +00:00
it('should search by parking', () => {
const expr = controller.exprBuilder('parking', '700-01');
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(expr).toEqual({'parking': '700-01'});
2022-10-05 13:13:48 +00:00
});
2022-10-11 07:13:29 +00:00
it('should search by shelving', () => {
const expr = controller.exprBuilder('shelving', 'AAA');
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(expr).toEqual({'shelving': 'AAA'});
2022-10-05 13:13:48 +00:00
});
2022-10-11 07:13:29 +00:00
it('should search by label', () => {
const expr = controller.exprBuilder('label', 0.17);
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(expr).toEqual({'label': 0.17});
});
it('should search by packing', () => {
const expr = controller.exprBuilder('packing', 10);
2022-10-05 13:13:48 +00:00
2022-10-11 07:13:29 +00:00
expect(expr).toEqual({'packing': 10});
2022-10-05 13:13:48 +00:00
});
});
});
});