Skip to content

Commit

Permalink
Merge pull request #15351 from robGardiner01/table-filter-equals-fix
Browse files Browse the repository at this point in the history
Bug #14978: Table filter integer does not equal decimal string
  • Loading branch information
cetincakiroglu authored Apr 26, 2024
2 parents 7df47bc + e52d297 commit f8189d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/app/components/api/filterservice.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { FilterService } from './filterservice';
describe('FilterService Suite', () => {
let data: any = [
{ brand: 'VW', year: 2012, color: { name: 'Orange' }, vin: 'dsad231ff' },
{ brand: 'Audi', year: 2011, color: { name: 'Black' }, vin: 'gwregre345' },
{ brand: 'Renault', year: 2005, color: { name: 'Black' }, vin: 'h354htr' },
{ brand: 'BMW', year: 2003, color: { name: 'Blue' }, vin: 'j6w54qgh' },
{ brand: 'Mercedes', year: 1995, color: { name: 'Red' }, vin: 'hrtwy34' },
{ brand: 'Volvo', year: 2005, color: { name: 'Orange' }, vin: 'jejtyj' },
{ brand: 'Honda', year: 2012, color: { name: 'Blue' }, vin: 'g43gr' },
{ brand: 'Jaguar', year: 2013, color: { name: 'Black' }, vin: 'greg34' },
{ brand: 'Ford', year: 2000, color: { name: 'White' }, vin: 'h54hw5' },
{ brand: 'Fiat', year: 2013, color: { name: 'Yellow' }, vin: '245t2s' }
{ brand: 'VW', year: 2012, color: { name: 'Orange' }, vin: 'dsad231ff', price: '1000.0' },
{ brand: 'Audi', year: 2011, color: { name: 'Black' }, vin: 'gwregre345', price: '4000.0' },
{ brand: 'Renault', year: 2005, color: { name: 'Black' }, vin: 'h354htr', price: '5000.0' },
{ brand: 'BMW', year: 2003, color: { name: 'Blue' }, vin: 'j6w54qgh', price: '3000.0000000' },
{ brand: 'Mercedes', year: 1995, color: { name: 'Red' }, vin: 'hrtwy34', price: '2000.0' },
{ brand: 'Volvo', year: 2005, color: { name: 'Orange' }, vin: 'jejtyj', price: '2000.0' },
{ brand: 'Honda', year: 2012, color: { name: 'Blue' }, vin: 'g43gr', price: '4000.0' },
{ brand: 'Jaguar', year: 2013, color: { name: 'Black' }, vin: 'greg34', price: '1000.0' },
{ brand: 'Ford', year: 2000, color: { name: 'White' }, vin: 'h54hw5', price: '2000.0' },
{ brand: 'Fiat', year: 2013, color: { name: 'Yellow' }, vin: '245t2s', price: '5000.0' }
];

let timeData = [{ date: 'Tue Aug 04 2019 00:00:00 GMT+0300 (GMT+03:00)' }, { date: 'Tue Aug 05 2019 00:00:00 GMT+0300 (GMT+03:00)' }, { date: 'Tue Aug 07 2019 00:00:00 GMT+0300 (GMT+03:00)' }];
Expand Down Expand Up @@ -48,6 +48,10 @@ describe('FilterService Suite', () => {
expect(filteredValue.length).toEqual(10);
filteredValue = filterService.filter(data, [''], 'BMW', 'equals');
expect(filteredValue.length).toEqual(0);
filteredValue = filterService.filter(data, ['price'], 3000, 'equals');
expect(filteredValue.length).toEqual(1);
filteredValue = filterService.filter(data, ['year'], 2012, 'equals');
expect(filteredValue.length).toEqual(2);
});
it('Should filter by notEquals', () => {
let filteredValue = filterService.filter(data, ['brand'], 'BMW', 'notEquals');
Expand All @@ -56,6 +60,10 @@ describe('FilterService Suite', () => {
expect(filteredValue.length).toEqual(0);
filteredValue = filterService.filter(data, [''], 'BMW', 'notEquals');
expect(filteredValue.length).toEqual(10);
filteredValue = filterService.filter(data, ['price'], 3000, 'notEquals');
expect(filteredValue.length).toEqual(9);
filteredValue = filterService.filter(data, ['year'], 2012, 'notEquals');
expect(filteredValue.length).toEqual(8);
});
it('Should filter by lt', () => {
let filteredValue = filterService.filter(timeData, ['date'], 'Tue Aug 05 2019 00:00:00 GMT+0300 (GMT+03:00)', 'lt');
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/api/filterservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class FilterService {
}

if (value.getTime && filter.getTime) return value.getTime() === filter.getTime();
else if (value == filter) return true;
else return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) == ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
},

Expand All @@ -106,6 +107,7 @@ export class FilterService {
}

if (value.getTime && filter.getTime) return value.getTime() !== filter.getTime();
else if (value == filter) return false;
else return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) != ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
},

Expand Down

0 comments on commit f8189d5

Please sign in to comment.