fix(bank): the search by bank was not differentiating between numerical values and string values
gitea/salix/pipeline/head This commit looks good Details

Refs: 3084
This commit is contained in:
Joan Sanchez 2021-09-03 14:00:47 +02:00
parent 559ff95fd7
commit 13f78359d5
7 changed files with 63 additions and 3 deletions

View File

@ -63,7 +63,7 @@
show-field="bank"
order="id"
value-field="id"
search-function="{or: [{id: $search}, {bank: {like: '%'+ $search +'%'}}]}">
search-function="$ctrl.bankSearchFunc($search)">
<tpl-item>{{id}}: {{bank}}</tpl-item>
</vn-autocomplete>
<vn-autocomplete

View File

@ -78,6 +78,12 @@ class Controller {
this.$.companies.refresh();
this.$.popover.show(event.target);
}
bankSearchFunc($search) {
return /^\d+$/.test($search)
? {id: $search}
: {bank: {like: '%' + $search + '%'}};
}
}
Controller.$inject = ['$scope', '$translate', 'vnConfig', 'vnAuth', 'vnToken'];

View File

@ -61,12 +61,28 @@ describe('Salix', () => {
});
describe('getImageUrl()', () => {
it('should return de url image', () => {
it('should return the url image', () => {
const url = $root.imagePath('user', '160x160', userId);
expect(url).toBeDefined();
expect(url).toEqual(`/api/Images/user/160x160/${userId}/download?access_token=null`);
});
});
describe('bankSearchFunc()', () => {
it('should return the filter by id property for an input of a number', () => {
const bankId = 1;
const result = controller.bankSearchFunc(bankId);
expect(result).toEqual({id: bankId});
});
it('should return the filter by bank property for an input of an string', () => {
const bankName = 'Bank of America';
const result = controller.bankSearchFunc(bankName);
expect(result).toEqual({bank: {like: '%' + bankName + '%'}});
});
});
});
});

View File

@ -33,7 +33,7 @@
fields="['accountingTypeFk']"
include="{relation: 'accountingType'}"
ng-model="$ctrl.bankFk"
search-function="{or: [{id: $search}, {bank: {like: '%'+ $search +'%'}}]}"
search-function="$ctrl.bankSearchFunc($search)"
selection="$ctrl.bankSelection"
order="id"
required="true">

View File

@ -137,6 +137,12 @@ class Controller extends Dialog {
}
});
}
bankSearchFunc($search) {
return /^\d+$/.test($search)
? {id: $search}
: {bank: {like: '%' + $search + '%'}};
}
}
Controller.$inject = ['$element', '$scope', '$transclude', 'vnReport'];

View File

@ -118,5 +118,21 @@ describe('Client', () => {
expect(controller.receipt.compensationAccount).toEqual('4000000003');
});
});
describe('bankSearchFunc()', () => {
it('should return the filter by id property for an input of a number', () => {
const bankId = 1;
const result = controller.bankSearchFunc(bankId);
expect(result).toEqual({id: bankId});
});
it('should return the filter by bank property for an input of an string', () => {
const bankName = 'Bank of America';
const result = controller.bankSearchFunc(bankName);
expect(result).toEqual({bank: {like: '%' + bankName + '%'}});
});
});
});
});

View File

@ -679,5 +679,21 @@ describe('Ticket', () => {
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
describe('itemSearchFunc()', () => {
it('should return the filter by id property for an input of a number', () => {
const itemId = 1;
const result = controller.itemSearchFunc(itemId);
expect(result).toEqual({id: itemId});
});
it('should return the filter by bank property for an input of an string', () => {
const itemName = 'Bow';
const result = controller.itemSearchFunc(itemName);
expect(result).toEqual({name: {like: '%' + itemName + '%'}});
});
});
});
});