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

View File

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

View File

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