/* eslint max-len: ["error", { "code": 150 }]*/ 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(' { it(`should call the buys patch route if the received buy has an ID`, () => { const buy = {id: 1, itemFk: 1, quantity: 1, packageFk: 1}; const query = `Buys/${buy.id}`; $httpBackend.expectPATCH(query).respond(200); controller.saveBuy(buy); $httpBackend.flush(); }); it(`should call the entry addBuy post route if the received buy has no ID`, () => { controller.entry = {id: 1}; const buy = {itemFk: 1, quantity: 1, packageFk: 1}; const query = `Entries/${controller.entry.id}/addBuy`; $httpBackend.expectPOST(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`, () => { const grouping = 1; const packing = 2; const buy = {id: 999, groupingMode: grouping}; const query = `Buys/${buy.id}`; $httpBackend.expectPATCH(query, {groupingMode: packing}).respond(200); controller.toggleGroupingMode(buy, 'packing'); $httpBackend.flush(); }); it(`should toggle grouping mode from packing to grouping`, () => { const grouping = 1; const packing = 2; const buy = {id: 999, groupingMode: packing}; const query = `Buys/${buy.id}`; $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`, () => { const noGrouping = 0; const packing = 2; const buy = {id: 999, groupingMode: packing}; const query = `Buys/${buy.id}`; $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`, () => { const noGrouping = 0; const grouping = 1; const buy = {id: 999, groupingMode: grouping}; const query = `Buys/${buy.id}`; $httpBackend.expectPATCH(query, {groupingMode: noGrouping}).respond(200); controller.toggleGroupingMode(buy, 'grouping'); $httpBackend.flush(); }); }); });