import './index'; describe('vnInvoiceOutDescriptor', () => { let controller; let $httpBackend; const invoiceOut = {id: 1}; beforeEach(ngModule('invoiceOut')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; controller = $componentController('vnInvoiceOutDescriptor', {$element: null}); })); describe('createInvoicePdf()', () => { it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); controller.invoiceOut = invoiceOut; $httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond(); controller.createInvoicePdf(); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('loadData()', () => { it(`should perform a get query to store the invoice in data into the controller`, () => { const id = 1; const response = {id: 1}; $httpBackend.expectGET(`InvoiceOuts/${id}`).respond(response); controller.id = id; $httpBackend.flush(); expect(controller.invoiceOut).toEqual(response); }); }); });