salix/modules/entry/front/buy/index/index.spec.js

104 lines
3.6 KiB
JavaScript
Raw Normal View History

/* eslint max-len: ["error", { "code": 150 }]*/
2021-04-28 08:32:24 +00:00
import './index.js';
describe('Entry buy', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('entry'));
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
let $element = $compile('<vn-entry-buy-index></vn-entry-buy-index')($rootScope);
controller = $componentController('vnEntryBuyIndex', {$element});
2021-07-02 12:12:37 +00:00
const params = _$httpParamSerializer_({filter: {limit: 20}});
$httpBackend.whenGET(`Entries//getBuys?${params}`).respond([{id: 1}]);
2021-04-28 08:32:24 +00:00
}));
describe('saveBuy()', () => {
it(`should call the buys patch route if the received buy has an ID`, () => {
2023-09-22 08:59:48 +00:00
const buy = {id: 1, itemFk: 1, quantity: 1, packagingFk: 1};
2021-04-28 08:32:24 +00:00
const query = `Buys/${buy.id}`;
$httpBackend.expectPATCH(query).respond(200);
controller.saveBuy(buy);
$httpBackend.flush();
});
});
describe('deleteBuys()', () => {
it(`should perform no queries if all buys to delete were not actual instances`, () => {
controller.buys = [
{checked: true},
{checked: true},
{checked: false}];
controller.deleteBuys();
expect(controller.buys.length).toEqual(1);
});
it(`should perform a query to delete as there's an actual instance at least`, () => {
controller.buys = [
{checked: true, id: 1},
{checked: true},
{checked: false}];
const query = 'Buys/deleteBuys';
$httpBackend.expectPOST(query).respond(200);
controller.deleteBuys();
$httpBackend.flush();
expect(controller.buys.length).toEqual(1);
});
});
describe('toggleGroupingMode()', () => {
it(`should toggle grouping mode from grouping to packing`, () => {
2022-02-08 08:27:39 +00:00
const grouping = 1;
const packing = 2;
const buy = {id: 999, groupingMode: grouping};
const query = `Buys/${buy.id}`;
2022-02-08 08:27:39 +00:00
$httpBackend.expectPATCH(query, {groupingMode: packing}).respond(200);
controller.toggleGroupingMode(buy, 'packing');
$httpBackend.flush();
});
it(`should toggle grouping mode from packing to grouping`, () => {
2022-02-08 08:27:39 +00:00
const grouping = 1;
const packing = 2;
const buy = {id: 999, groupingMode: packing};
const query = `Buys/${buy.id}`;
2022-02-08 08:27:39 +00:00
$httpBackend.expectPATCH(query, {groupingMode: grouping}).respond(200);
controller.toggleGroupingMode(buy, 'grouping');
$httpBackend.flush();
});
it(`should toggle off the grouping mode if it was packing to packing`, () => {
2022-02-08 08:27:39 +00:00
const noGrouping = 0;
const packing = 2;
const buy = {id: 999, groupingMode: packing};
const query = `Buys/${buy.id}`;
2022-02-08 08:27:39 +00:00
$httpBackend.expectPATCH(query, {groupingMode: noGrouping}).respond(200);
controller.toggleGroupingMode(buy, 'packing');
$httpBackend.flush();
});
it(`should toggle off the grouping mode if it was grouping to grouping`, () => {
2022-02-08 08:27:39 +00:00
const noGrouping = 0;
const grouping = 1;
const buy = {id: 999, groupingMode: grouping};
const query = `Buys/${buy.id}`;
2022-02-08 08:27:39 +00:00
$httpBackend.expectPATCH(query, {groupingMode: noGrouping}).respond(200);
controller.toggleGroupingMode(buy, 'grouping');
$httpBackend.flush();
});
});
2021-04-28 08:32:24 +00:00
});