import './index.js'; import crudModel from 'core/mocks/crud-model'; describe('Client', () => { describe('Component vnClientConsumption', () => { let $scope; let controller; let $httpParamSerializer; let $httpBackend; beforeEach(ngModule('client')); 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: 1101, from: now, to: now }; const serializedParams = $httpParamSerializer(expectedParams); const path = `api/report/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: 1101, from: now, to: now }; const serializedParams = $httpParamSerializer(expectedParams); const path = `email/campaign-metrics?${serializedParams}`; $httpBackend.expect('GET', path).respond({}); controller.sendEmail(); $httpBackend.flush(); }); }); }); });