mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
parent
ba710dc816
commit
4beda8e55e
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user