Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,20 @@ describe('GridOdataService', () => {
expect(query).toBe(expectation);
});

it('should return a query with a CSV string when the filter operator is IN ', () => {
const expectation = `$top=10&$filter=(Gender eq 'female' or Gender eq 'ma%2Fle')`;
const mockColumn = { id: 'gender', field: 'gender' } as Column;
const mockColumnFilters = {
gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], operator: 'IN' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query with a CSV string when the filter operator is IN for numeric column type', () => {
const expectation = `$top=10&$filter=(Id eq 100 or Id eq 101)`;
const mockColumn = { id: 'id', field: 'id', type: FieldType.number } as Column;
Expand Down Expand Up @@ -748,6 +762,20 @@ describe('GridOdataService', () => {
expect(query).toBe(expectation);
});

it('should return a query with a CSV string when the filter operator is NOT_IN', () => {
const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'ma%2Fle')`;
const mockColumn = { id: 'gender', field: 'gender' } as Column;
const mockColumnFilters = {
gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], operator: OperatorType.notIn },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query with a CSV string and use the operator from the Column Definition Operator when provided', () => {
const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'male')`;
const mockColumn = { id: 'gender', field: 'gender', filter: { operator: OperatorType.notIn } } as Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class GridOdataService implements BackendService {
// example:: (Stage eq "Expired" or Stage eq "Renewal")
for (let j = 0, lnj = searchTerms.length; j < lnj; j++) {
if (fieldType === FieldType.string) {
const searchVal = searchTerms[j].replace(`'`, `''`);
const searchVal = encodeURIComponent(searchTerms[j].replace(`'`, `''`));
tmpSearchTerms.push(`${fieldName} eq '${searchVal}'`);
} else {
// Single quote escape is not needed for non string type
Expand All @@ -342,7 +342,7 @@ export class GridOdataService implements BackendService {
} else {
// example:: (Stage ne "Expired" and Stage ne "Renewal")
for (let k = 0, lnk = searchTerms.length; k < lnk; k++) {
const searchVal = searchTerms[k].replace(`'`, `''`);
const searchVal = encodeURIComponent(searchTerms[k].replace(`'`, `''`));
tmpSearchTerms.push(`${fieldName} ne '${searchVal}'`);
}
searchBy = tmpSearchTerms.join(' and ');
Expand Down