feat: add testFront
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-10-11 09:13:29 +02:00
parent 1a38fc307f
commit bfefec397e
1 changed files with 39 additions and 79 deletions

View File

@ -1,120 +1,80 @@
import './index'; import './index';
import crudModel from 'core/mocks/crud-model'; import crudModel from 'core/mocks/crud-model';
describe('client defaulter', () => { describe('item shelving', () => {
describe('Component vnClientDefaulter', () => { describe('Component vnItemShelving', () => {
let controller; let controller;
let $httpBackend; let $httpBackend;
beforeEach(ngModule('client')); beforeEach(ngModule('item'));
beforeEach(inject(($componentController, _$httpBackend_) => { beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-defaulter></vn-client-defaulter>'); const $element = angular.element('<vn-item-shelving></vn-item-shelving>');
controller = $componentController('vnClientDefaulter', {$element}); controller = $componentController('vnItemShelving', {$element});
controller.$.model = crudModel; controller.$.model = crudModel;
controller.$.model.data = [ controller.$.model.data = [
{clientFk: 1101, amount: 125}, {itemShelvingFk: 1, packing: 10, stock: 1},
{clientFk: 1102, amount: 500}, {itemShelvingFk: 2, packing: 12, stock: 5},
{clientFk: 1103, amount: 250} {itemShelvingFk: 4, packing: 20, stock: 10}
]; ];
const modelData = controller.$.model.data;
modelData[0].checked = true;
modelData[1].checked = true;
})); }));
describe('checked() getter', () => { describe('checked() getter', () => {
it('should return the checked lines', () => { it('should return a the selected rows', () => {
const data = controller.$.model.data; const result = controller.checked;
data[1].checked = true;
data[2].checked = true;
const checkedRows = controller.checked; expect(result).toEqual(expect.arrayContaining([1, 2]));
const firstCheckedRow = checkedRows[0];
const secondCheckedRow = checkedRows[1];
expect(firstCheckedRow.clientFk).toEqual(1102);
expect(secondCheckedRow.clientFk).toEqual(1103);
}); });
}); });
describe('chipColor()', () => { describe('calculateTotals()', () => {
it('should return undefined when the date is the present', () => { it('should calculate the total of labels', () => {
let today = new Date(); controller.calculateTotals();
let result = controller.chipColor(today);
expect(result).toEqual(undefined); expect(controller.labelTotal).toEqual(1.0166666666666666);
});
it('should return warning when the date is 10 days in the past', () => {
let pastDate = new Date();
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', () => {
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 21);
let result = controller.chipColor(pastDate);
expect(result).toEqual('alert');
}); });
}); });
describe('onResponse()', () => { describe('onRemove()', () => {
it('should return error for empty message', () => { it('shoud remove the selected lines', () => {
let error; jest.spyOn(controller.$.model, 'refresh');
try { const expectedParams = {itemShelvingIds: [1, 2]};
controller.onResponse();
} catch (e) {
error = e;
}
expect(error).toBeDefined(); $httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200);
expect(error.message).toBe(`The message can't be empty`); controller.onRemove();
});
it('should return saved message', () => {
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}];
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('GET', `Defaulters/filter`).respond(200);
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
controller.onResponse();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); expect(controller.$.model.refresh).toHaveBeenCalled();
}); });
}); });
describe('exprBuilder()', () => { describe('exprBuilder()', () => {
it('should search by sales person', () => { it('should search by parking', () => {
const expr = controller.exprBuilder('salesPersonFk', '5'); const expr = controller.exprBuilder('parking', '700-01');
expect(expr).toEqual({'d.salesPersonFk': '5'}); expect(expr).toEqual({'parking': '700-01'});
}); });
it('should search by client', () => { it('should search by shelving', () => {
const expr = controller.exprBuilder('clientFk', '5'); const expr = controller.exprBuilder('shelving', 'AAA');
expect(expr).toEqual({'d.clientFk': '5'}); expect(expr).toEqual({'shelving': 'AAA'});
});
}); });
describe('getBalanceDueTotal()', () => { it('should search by label', () => {
it('should return balance due total', () => { const expr = controller.exprBuilder('label', 0.17);
const defaulters = controller.$.model.data;
$httpBackend.when('GET', `Defaulters/filter`).respond(defaulters);
controller.getBalanceDueTotal(); expect(expr).toEqual({'label': 0.17});
$httpBackend.flush(); });
expect(controller.balanceDueTotal).toEqual(875); it('should search by packing', () => {
const expr = controller.exprBuilder('packing', 10);
expect(expr).toEqual({'packing': 10});
}); });
}); });
}); });