Clear autocomplete results/errors between searches

Refs #737
This commit is contained in:
Will Abson 2016-10-04 16:17:53 +01:00
parent ba710dc816
commit 4beda8e55e
2 changed files with 41 additions and 0 deletions

View File

@ -136,6 +136,25 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
expect(component.displaySearchResults).toHaveBeenCalledWith(searchTerm.currentValue);
});
it('should clear results straight away when a new search term is entered', (done) => {
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
spyOn(searchService, 'getSearchNodesPromise')
.and.returnValue(Promise.resolve(result));
component.resultsEmitter.subscribe(x => {
alfrescoSearchComponentFixture.detectChanges();
component.searchTerm = 'searchTerm2';
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
alfrescoSearchComponentFixture.detectChanges();
expect(element.querySelectorAll('table[data-automation-id="autocomplete_results"] tbody tr').length).toBe(0);
done();
});
component.searchTerm = 'searchTerm';
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''} });
});
it('should display the returned search results', (done) => {
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
@ -214,6 +233,26 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
});
it('should clear errors straight away when a new search is performed', (done) => {
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
spyOn(searchService, 'getSearchNodesPromise')
.and.returnValue(Promise.reject(errorJson));
component.errorEmitter.subscribe(() => {
alfrescoSearchComponentFixture.detectChanges();
component.searchTerm = 'searchTerm2';
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
alfrescoSearchComponentFixture.detectChanges();
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
expect(errorEl).toBeNull();
done();
});
component.searchTerm = 'searchTerm';
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
});
it('should emit preview when file item clicked', (done) => {
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);

View File

@ -62,6 +62,8 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
ngOnChanges(changes) {
if (changes.searchTerm) {
this.results = null;
this.errorMessage = null;
this.displaySearchResults(changes.searchTerm.currentValue);
}
}