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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('balanceDueTotal() getter', () => {
|
|
|
|
it('should return balance due total', () => {
|
|
|
|
const data = controller.$.model.data;
|
2022-02-21 14:11:39 +00:00
|
|
|
const expectedAmount = data[0].amount + data[1].amount + data[2].amount;
|
2022-01-25 13:27:30 +00:00
|
|
|
|
|
|
|
const result = controller.balanceDueTotal;
|
|
|
|
|
|
|
|
expect(result).toEqual(expectedAmount);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-21 14:11:39 +00:00
|
|
|
describe('chipColor()', () => {
|
|
|
|
it('should return undefined when the date is the present', () => {
|
2022-03-30 10:45:01 +00:00
|
|
|
let today = new Date('2022-01-19');
|
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', () => {
|
2022-03-30 10:45:01 +00:00
|
|
|
let pastDate = new Date('2022-01-19');
|
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', () => {
|
2022-03-30 10:45:01 +00:00
|
|
|
let pastDate = new Date('2022-01-19');
|
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}];
|
|
|
|
|
2022-01-25 13:27:30 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
2022-02-01 07:49:56 +00:00
|
|
|
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
|
|
|
|
|
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
|
|
|
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('exprBuilder()', () => {
|
|
|
|
it('should search by sales person', () => {
|
|
|
|
let expr = controller.exprBuilder('salesPersonFk', '5');
|
|
|
|
|
|
|
|
expect(expr).toEqual({'d.salesPersonFk': '5'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should search by client name', () => {
|
|
|
|
let expr = controller.exprBuilder('clientName', '1foo');
|
|
|
|
|
|
|
|
expect(expr).toEqual({'d.clientName': '1foo'});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|