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

99 lines
3.4 KiB
JavaScript
Raw Normal View History

2022-02-14 07:44:22 +00:00
import './index';
import crudModel from 'core/mocks/crud-model';
describe('Client notification', () => {
describe('Component vnClientNotification', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-notification></vn-client-notification>');
controller = $componentController('vnClientNotification', {$element});
controller.$.model = crudModel;
controller.$.model.data = [
{id: 1101},
{id: 1102},
{id: 1103}
];
$httpBackend.expect('GET', `Campaigns/upcoming`).respond(200, {id: 1});
}));
describe('checked() getter', () => {
it('should return the checked lines', () => {
const data = controller.$.model.data;
data[1].$checked = true;
data[2].$checked = true;
const checkedRows = controller.checked;
const firstCheckedRow = checkedRows[0];
const secondCheckedRow = checkedRows[1];
expect(firstCheckedRow.id).toEqual(1102);
expect(secondCheckedRow.id).toEqual(1103);
});
});
describe('campaignSelection() setter', () => {
it('should set the campaign from and to properties', () => {
const dated = new Date();
controller.campaignSelection = {
dated: dated,
scopeDays: 14
};
const expectedDateTo = new Date(dated);
expectedDateTo.setDate(expectedDateTo.getDate() - 14);
const campaign = controller.campaign;
expect(campaign.from).toEqual(expectedDateTo);
expect(campaign.to).toEqual(dated);
});
});
describe('onSendClientConsumption()', () => {
it('should return saved message', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
controller.$.filters = {hide: () => {}};
controller.campaign = {
from: new Date(),
to: new Date()
};
const data = controller.$.model.data;
data[0].$checked = true;
data[1].$checked = true;
const params = Object.assign({
2022-10-04 05:41:40 +00:00
clients: [1101, 1102]
2022-02-14 07:44:22 +00:00
}, controller.campaign);
2022-10-04 05:41:40 +00:00
$httpBackend.expect('POST', `ClientConsumptionQueues`, {params}).respond(200, params);
2022-02-14 07:44:22 +00:00
controller.onSendClientConsumption();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Notifications sent!');
});
});
describe('exprBuilder()', () => {
it('should search by sales person', () => {
let expr = controller.exprBuilder('salesPersonFk', '5');
expect(expr).toEqual({'salesPersonFk': '5'});
});
it('should search by client social name', () => {
let expr = controller.exprBuilder('socialName', '1foo');
expect(expr).toEqual({'socialName': {like: '%1foo%'}});
});
});
});
});