salix/modules/client/front/consumption/index.spec.js

73 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-06-10 11:35:41 +00:00
import './index.js';
import crudModel from 'core/mocks/crud-model';
2020-06-12 07:18:19 +00:00
describe('Client', () => {
describe('Component vnClientConsumption', () => {
2020-06-10 11:35:41 +00:00
let $scope;
let controller;
2020-06-12 07:18:19 +00:00
let $httpParamSerializer;
let $httpBackend;
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
beforeEach(ngModule('client'));
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
2020-06-10 11:35:41 +00:00
$scope = $rootScope.$new();
2020-06-12 07:18:19 +00:00
$httpParamSerializer = _$httpParamSerializer_;
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-consumption></vn-client-consumption');
controller = $componentController('vnClientConsumption', {$element, $scope});
2020-06-10 11:35:41 +00:00
controller.$.model = crudModel;
2020-06-12 07:18:19 +00:00
controller.client = {
id: 101
};
2020-06-10 11:35:41 +00:00
}));
2020-06-12 07:18:19 +00:00
describe('showReport()', () => {
it('should call the window.open function', () => {
jest.spyOn(window, 'open').mockReturnThis();
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
const now = new Date();
controller.$.model.userParams = {
from: now,
to: now
};
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
controller.showReport();
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
const expectedParams = {
recipientId: 101,
from: now,
to: now
};
const serializedParams = $httpParamSerializer(expectedParams);
const path = `api/report/campaign-metrics?${serializedParams}`;
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
expect(window.open).toHaveBeenCalledWith(path);
2020-06-10 11:35:41 +00:00
});
});
2020-06-12 07:18:19 +00:00
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: 101,
from: now,
to: now
};
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
const serializedParams = $httpParamSerializer(expectedParams);
const path = `email/campaign-metrics?${serializedParams}`;
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
$httpBackend.expect('GET', path).respond({});
controller.sendEmail();
$httpBackend.flush();
2020-06-10 11:35:41 +00:00
});
});
});
});