73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
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('<vn-client-consumption></vn-client-consumption');
|
|
controller = $componentController('vnClientConsumption', {$element, $scope});
|
|
controller.$.model = crudModel;
|
|
controller.client = {
|
|
id: 1101
|
|
};
|
|
}));
|
|
|
|
describe('showReport()', () => {
|
|
it('should call the window.open function', () => {
|
|
jest.spyOn(window, 'open').mockReturnThis();
|
|
|
|
const now = new Date('2022-01-19');
|
|
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('2022-01-19');
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|