2022-01-25 13:27:30 +00:00
|
|
|
import './index';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
|
|
|
|
describe('client defaulter', () => {
|
2022-02-25 09:34:17 +00:00
|
|
|
describe('Component vnClientDefaulter', () => {
|
2022-01-25 13:27:30 +00:00
|
|
|
let controller;
|
2022-02-01 07:49:56 +00:00
|
|
|
let $httpBackend;
|
2022-01-25 13:27:30 +00:00
|
|
|
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
|
2022-02-01 07:49:56 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2022-01-25 13:27:30 +00:00
|
|
|
const $element = angular.element('<vn-client-defaulter></vn-client-defaulter>');
|
2022-02-25 09:34:17 +00:00
|
|
|
controller = $componentController('vnClientDefaulter', {$element});
|
2022-01-25 13:27:30 +00:00
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$.model.data = [
|
|
|
|
{clientFk: 1101, amount: 125},
|
|
|
|
{clientFk: 1102, amount: 500},
|
|
|
|
{clientFk: 1103, amount: 250}
|
|
|
|
];
|
|
|
|
}));
|
|
|
|
|
|
|
|
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.clientFk).toEqual(1102);
|
|
|
|
expect(secondCheckedRow.clientFk).toEqual(1103);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-21 14:11:39 +00:00
|
|
|
describe('chipColor()', () => {
|
|
|
|
it('should return undefined when the date is the present', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2022-02-21 14:11:39 +00:00
|
|
|
let result = controller.chipColor(today);
|
|
|
|
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return warning when the date is 10 days in the past', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let pastDate = Date.vnNew();
|
2022-02-21 14:11:39 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 11);
|
|
|
|
let result = controller.chipColor(pastDate);
|
|
|
|
|
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return alert when the date is 20 days in the past', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let pastDate = Date.vnNew();
|
2022-02-21 14:11:39 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 21);
|
|
|
|
let result = controller.chipColor(pastDate);
|
|
|
|
|
|
|
|
expect(result).toEqual('alert');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-25 13:27:30 +00:00
|
|
|
describe('onResponse()', () => {
|
|
|
|
it('should return error for empty message', () => {
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
controller.onResponse();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.message).toBe(`The message can't be empty`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return saved message', () => {
|
2022-02-01 07:49:56 +00:00
|
|
|
const data = controller.$.model.data;
|
|
|
|
data[1].checked = true;
|
|
|
|
controller.defaulter = {observation: 'My new observation'};
|
|
|
|
|
|
|
|
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
|
|
|
|
|
2023-03-24 09:05:17 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2022-05-12 12:18:16 +00:00
|
|
|
$httpBackend.expect('GET', `Defaulters/filter`).respond(200);
|
2022-02-01 07:49:56 +00:00
|
|
|
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
|
2023-04-04 12:09:55 +00:00
|
|
|
$httpBackend.expect('POST', `Defaulters/observationEmail`).respond(200);
|
2022-02-01 07:49:56 +00:00
|
|
|
|
2022-01-25 13:27:30 +00:00
|
|
|
controller.onResponse();
|
2022-02-01 07:49:56 +00:00
|
|
|
$httpBackend.flush();
|
2022-01-25 13:27:30 +00:00
|
|
|
|
2023-03-24 09:05:17 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Observation saved!');
|
2022-01-25 13:27:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('exprBuilder()', () => {
|
|
|
|
it('should search by sales person', () => {
|
2022-04-08 06:52:21 +00:00
|
|
|
const expr = controller.exprBuilder('salesPersonFk', '5');
|
2022-01-25 13:27:30 +00:00
|
|
|
|
|
|
|
expect(expr).toEqual({'d.salesPersonFk': '5'});
|
|
|
|
});
|
|
|
|
|
2022-04-08 06:52:21 +00:00
|
|
|
it('should search by client', () => {
|
|
|
|
const expr = controller.exprBuilder('clientFk', '5');
|
2022-01-25 13:27:30 +00:00
|
|
|
|
2022-04-08 06:52:21 +00:00
|
|
|
expect(expr).toEqual({'d.clientFk': '5'});
|
2022-01-25 13:27:30 +00:00
|
|
|
});
|
|
|
|
});
|
2022-06-13 05:44:21 +00:00
|
|
|
|
|
|
|
describe('getBalanceDueTotal()', () => {
|
|
|
|
it('should return balance due total', () => {
|
|
|
|
const defaulters = controller.$.model.data;
|
|
|
|
$httpBackend.when('GET', `Defaulters/filter`).respond(defaulters);
|
|
|
|
|
|
|
|
controller.getBalanceDueTotal();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.balanceDueTotal).toEqual(875);
|
|
|
|
});
|
|
|
|
});
|
2023-03-16 12:55:21 +00:00
|
|
|
|
|
|
|
describe('dateRange()', () => {
|
|
|
|
it('should return two dates with the hours at the start and end of the given date', () => {
|
|
|
|
const now = Date.vnNew();
|
|
|
|
|
|
|
|
const today = now.getDate();
|
|
|
|
|
|
|
|
const dateRange = controller.dateRange(now);
|
|
|
|
const start = dateRange[0].toString();
|
|
|
|
const end = dateRange[1].toString();
|
|
|
|
|
|
|
|
expect(start).toContain(today);
|
|
|
|
expect(start).toContain('00:00:00');
|
|
|
|
|
|
|
|
expect(end).toContain(today);
|
|
|
|
expect(end).toContain('23:59:59');
|
|
|
|
});
|
|
|
|
});
|
2023-03-22 09:13:59 +00:00
|
|
|
|
|
|
|
describe('reCheck()', () => {
|
|
|
|
it(`should recheck buys`, () => {
|
|
|
|
controller.$.model.data = [
|
|
|
|
{checked: false, clientFk: 1},
|
|
|
|
{checked: false, clientFk: 2},
|
|
|
|
{checked: false, clientFk: 3},
|
|
|
|
{checked: false, clientFk: 4},
|
|
|
|
];
|
|
|
|
controller.checkedDefaulers = [1, 2];
|
|
|
|
|
|
|
|
controller.reCheck();
|
|
|
|
|
|
|
|
expect(controller.$.model.data[0].checked).toEqual(true);
|
|
|
|
expect(controller.$.model.data[1].checked).toEqual(true);
|
|
|
|
expect(controller.$.model.data[2].checked).toEqual(false);
|
|
|
|
expect(controller.$.model.data[3].checked).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('saveChecked()', () => {
|
|
|
|
it(`should check buy`, () => {
|
|
|
|
const buyCheck = 3;
|
|
|
|
controller.checkedDefaulers = [1, 2];
|
|
|
|
|
|
|
|
controller.saveChecked(buyCheck);
|
|
|
|
|
|
|
|
expect(controller.checkedDefaulers[2]).toEqual(buyCheck);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should uncheck buy`, () => {
|
|
|
|
const buyUncheck = 3;
|
|
|
|
controller.checkedDefaulers = [1, 2, 3];
|
|
|
|
|
|
|
|
controller.saveChecked(buyUncheck);
|
|
|
|
|
|
|
|
expect(controller.checkedDefaulers[2]).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
2022-01-25 13:27:30 +00:00
|
|
|
});
|
|
|
|
});
|