mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -110,6 +110,21 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
updateSearchTerm('searchTerm');
|
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) => {
|
it('should display the correct thumbnail for result items', (done) => {
|
||||||
|
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
|
@@ -40,6 +40,9 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
|||||||
@Input()
|
@Input()
|
||||||
ngClass: any;
|
ngClass: any;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
maxResults: number = 5;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
preview: EventEmitter<any> = new EventEmitter();
|
preview: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
@@ -83,13 +86,13 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
|||||||
* Loads and displays search results
|
* Loads and displays search results
|
||||||
* @param searchTerm Search query entered by user
|
* @param searchTerm Search query entered by user
|
||||||
*/
|
*/
|
||||||
public displaySearchResults(searchTerm) {
|
private displaySearchResults(searchTerm) {
|
||||||
if (searchTerm !== null && searchTerm !== '') {
|
if (searchTerm !== null && searchTerm !== '') {
|
||||||
this.alfrescoSearchService
|
this.alfrescoSearchService
|
||||||
.getLiveSearchResults(searchTerm)
|
.getLiveSearchResults(searchTerm)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
results => {
|
results => {
|
||||||
this.results = results.list.entries;
|
this.results = results.list.entries.slice(0, this.maxResults);
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
this.resultsEmitter.emit(this.results);
|
this.resultsEmitter.emit(this.results);
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user