mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
@@ -110,6 +110,21 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
updateSearchTerm('searchTerm');
|
||||
});
|
||||
|
||||
it('should limit the number of returned search results to the configured maximum', (done) => {
|
||||
|
||||
spyOn(searchService, 'getSearchNodesPromise')
|
||||
.and.returnValue(Promise.resolve(results));
|
||||
|
||||
component.resultsEmitter.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelectorAll('table[data-automation-id="autocomplete_results"] tbody tr').length).toBe(2);
|
||||
done();
|
||||
});
|
||||
|
||||
component.maxResults = 2;
|
||||
updateSearchTerm('searchTerm');
|
||||
});
|
||||
|
||||
it('should display the correct thumbnail for result items', (done) => {
|
||||
|
||||
spyOn(searchService, 'getSearchNodesPromise')
|
||||
|
@@ -40,6 +40,9 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
||||
@Input()
|
||||
ngClass: any;
|
||||
|
||||
@Input()
|
||||
maxResults: number = 5;
|
||||
|
||||
@Output()
|
||||
preview: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
@@ -83,13 +86,13 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
||||
* Loads and displays search results
|
||||
* @param searchTerm Search query entered by user
|
||||
*/
|
||||
public displaySearchResults(searchTerm) {
|
||||
private displaySearchResults(searchTerm) {
|
||||
if (searchTerm !== null && searchTerm !== '') {
|
||||
this.alfrescoSearchService
|
||||
.getLiveSearchResults(searchTerm)
|
||||
.subscribe(
|
||||
results => {
|
||||
this.results = results.list.entries;
|
||||
this.results = results.list.entries.slice(0, this.maxResults);
|
||||
this.errorMessage = null;
|
||||
this.resultsEmitter.emit(this.results);
|
||||
},
|
||||
|
Reference in New Issue
Block a user