import './index'; describe('InvoiceOut', () => { describe('Component vnInvoiceOutManual', () => { let controller; let $httpBackend; beforeEach(ngModule('invoiceOut')); beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; let $scope = $rootScope.$new(); const $element = angular.element(''); const $transclude = { $$boundTransclude: { $$slots: [] } }; controller = $componentController('vnInvoiceOutManual', {$element, $scope, $transclude}); })); describe('responseHandler()', () => { it('should throw an error when clientFk property is set and the maxShipped is not filled', () => { jest.spyOn(controller.vnApp, 'showError'); controller.invoice = { clientFk: 1101, serial: 'T', taxArea: 'B' }; controller.responseHandler('accept'); expect(controller.vnApp.showError).toHaveBeenCalledWith(`Client and the max shipped should be filled`); }); it('should throw an error when some required fields are not filled in', () => { jest.spyOn(controller.vnApp, 'showError'); controller.invoice = { ticketFk: 1101 }; controller.responseHandler('accept'); expect(controller.vnApp.showError).toHaveBeenCalledWith(`Some fields are required`); }); it('should make an http POST query and then call to the parent showSuccess() method', () => { jest.spyOn(controller.vnApp, 'showSuccess'); controller.invoice = { ticketFk: 1101, serial: 'T', taxArea: 'B' }; $httpBackend.expect('POST', `InvoiceOuts/createManualInvoice`).respond({id: 1}); controller.responseHandler('accept'); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); });