[ACS-7338] Fix search input formatting for asterisk (#9459)

* fix: double asterisk formatting for search input

* fix: double asterisk formatting for search input

* fix: double asterisk formatting for search input
This commit is contained in:
Denys Vuika
2024-03-25 09:39:35 -04:00
committed by GitHub
parent cf8d92f533
commit c4343c1332
2 changed files with 14 additions and 0 deletions

View File

@@ -84,6 +84,15 @@ describe('SearchInputComponent', () => {
expect(formatted).toBe('(cm:name:"test*")');
});
it('should not append asterisk if one is already provided', async () => {
let formatted = '';
component.changed.subscribe((val) => (formatted = val));
await setInputValue('*');
expect(formatted).toBe('(cm:name:"*")');
});
it('should format with AND by default', async () => {
let formatted = '';
component.changed.subscribe((val) => (formatted = val));

View File

@@ -100,6 +100,11 @@ export class SearchInputComponent {
term = term.substring(1);
}
if (term === '*') {
prefix = '';
suffix = '';
}
return '(' + fields.map((field) => `${prefix}${field}:"${term}${suffix}"`).join(' OR ') + ')';
}
}