import './index.js'; import crudModel from 'core/mocks/crud-model'; describe('Supplier', () => { describe('Component vnSupplierConsumption', () => { let $scope; let controller; let $httpParamSerializer; let $httpBackend; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$httpParamSerializer_, _$httpBackend_) => { $scope = $rootScope.$new(); $httpParamSerializer = _$httpParamSerializer_; $httpBackend = _$httpBackend_; const $element = angular.element(' { it('should call the window.open function', () => { jest.spyOn(window, 'open').mockReturnThis(); const now = new Date(); controller.$.model.userParams = { from: now, to: now }; controller.showReport(); const expectedParams = { recipientId: 2, from: now, to: now }; const serializedParams = $httpParamSerializer(expectedParams); const path = `api/report/supplier-campaign-metrics?${serializedParams}`; expect(window.open).toHaveBeenCalledWith(path); }); }); describe('sendEmail()', () => { it('should make a GET query sending the report', () => { const now = new Date(); controller.$.model.userParams = { from: now, to: now }; const expectedParams = { recipientId: 2, from: now, to: now }; const serializedParams = $httpParamSerializer(expectedParams); const path = `email/supplier-campaign-metrics?${serializedParams}`; $httpBackend.expect('GET', path).respond({}); controller.sendEmail(); $httpBackend.flush(); }); }); }); });