78991: Also test SearchOptions.fixedFilter

This commit is contained in:
Yura Bondarenko
2021-05-04 10:44:06 +02:00
parent e682997195
commit b9a8bfb2bd
3 changed files with 14 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ describe('PaginatedSearchOptions', () => {
new SearchFilter('f.example', ['another value', 'second value']), new SearchFilter('f.example', ['another value', 'second value']),
new SearchFilter('f.range', ['[2002 TO 2021]'], 'equals'), new SearchFilter('f.range', ['[2002 TO 2021]'], 'equals'),
]; ];
const fixedFilter = 'f.fixed=1234 5678,equals';
const query = 'search query'; const query = 'search query';
const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47';
const baseUrl = 'www.rest.com'; const baseUrl = 'www.rest.com';
@@ -23,7 +24,8 @@ describe('PaginatedSearchOptions', () => {
filters: filters, filters: filters,
query: query, query: query,
scope: scope, scope: scope,
dsoTypes: [DSpaceObjectType.ITEM] dsoTypes: [DSpaceObjectType.ITEM],
fixedFilter: fixedFilter,
}); });
}); });
@@ -35,6 +37,7 @@ describe('PaginatedSearchOptions', () => {
'sort=test.field,DESC&' + 'sort=test.field,DESC&' +
'page=0&' + 'page=0&' +
'size=40&' + 'size=40&' +
'f.fixed=1234%205678,equals&' +
'query=search%20query&' + 'query=search%20query&' +
'scope=0fde1ecb-82cc-425a-b600-ac3576d76b47&' + 'scope=0fde1ecb-82cc-425a-b600-ac3576d76b47&' +
'dsoType=ITEM&' + 'dsoType=ITEM&' +

View File

@@ -11,11 +11,18 @@ describe('SearchOptions', () => {
new SearchFilter('f.example', ['another value', 'second value']), new SearchFilter('f.example', ['another value', 'second value']),
new SearchFilter('f.range', ['[2002 TO 2021]'], 'equals'), new SearchFilter('f.range', ['[2002 TO 2021]'], 'equals'),
]; ];
const fixedFilter = 'f.fixed=1234 5678,equals';
const query = 'search query'; const query = 'search query';
const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47';
const baseUrl = 'www.rest.com'; const baseUrl = 'www.rest.com';
beforeEach(() => { beforeEach(() => {
options = new SearchOptions({ filters: filters, query: query, scope: scope, dsoTypes: [DSpaceObjectType.ITEM] }); options = new SearchOptions({
filters: filters,
query: query,
scope: scope,
dsoTypes: [DSpaceObjectType.ITEM],
fixedFilter: fixedFilter,
});
}); });
describe('when toRestUrl is called', () => { describe('when toRestUrl is called', () => {
@@ -23,6 +30,7 @@ describe('SearchOptions', () => {
it('should generate a string with all parameters that are present', () => { it('should generate a string with all parameters that are present', () => {
const outcome = options.toRestUrl(baseUrl); const outcome = options.toRestUrl(baseUrl);
expect(outcome).toEqual('www.rest.com?' + expect(outcome).toEqual('www.rest.com?' +
'f.fixed=1234%205678,equals&' +
'query=search%20query&' + 'query=search%20query&' +
'scope=0fde1ecb-82cc-425a-b600-ac3576d76b47&' + 'scope=0fde1ecb-82cc-425a-b600-ac3576d76b47&' +
'dsoType=ITEM&' + 'dsoType=ITEM&' +

View File

@@ -45,7 +45,7 @@ export class SearchOptions {
const match = this.fixedFilter.match(/^([^=]+=)(.+)$/); const match = this.fixedFilter.match(/^([^=]+=)(.+)$/);
if (match) { if (match) {
fixedFilter = match[1] + encodeURIComponent(match[2]); fixedFilter = match[1] + encodeURIComponent(match[2]).replace(/%2C/g, ',');
} else { } else {
fixedFilter = encodeURIComponent(this.fixedFilter); fixedFilter = encodeURIComponent(this.fixedFilter);
} }