Ensure maximum number of results is shown in FAYT results

Refs #371
This commit is contained in:
Will Abson
2016-10-26 13:10:56 +01:00
parent a8bea1800b
commit 3f440215b9
2 changed files with 20 additions and 2 deletions

View File

@@ -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')

View File

@@ -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);
},