mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
parent
dda838be5e
commit
b200eab466
@ -31,7 +31,7 @@ import {
|
|||||||
|
|
||||||
describe('AlfrescoSearchAutocompleteComponent', () => {
|
describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||||
|
|
||||||
let alfrescoSearchComponentFixture: ComponentFixture<AlfrescoSearchAutocompleteComponent>, element: HTMLElement;
|
let fixture: ComponentFixture<AlfrescoSearchAutocompleteComponent>, element: HTMLElement;
|
||||||
let component: AlfrescoSearchAutocompleteComponent;
|
let component: AlfrescoSearchAutocompleteComponent;
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
@ -110,16 +110,16 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
AlfrescoSearchService
|
AlfrescoSearchService
|
||||||
]
|
]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
alfrescoSearchComponentFixture = TestBed.createComponent(AlfrescoSearchAutocompleteComponent);
|
fixture = TestBed.createComponent(AlfrescoSearchAutocompleteComponent);
|
||||||
component = alfrescoSearchComponentFixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = alfrescoSearchComponentFixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should setup i18n folder', () => {
|
it('should setup i18n folder', () => {
|
||||||
let translationService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoTranslationService);
|
let translationService = fixture.debugElement.injector.get(AlfrescoTranslationService);
|
||||||
spyOn(translationService, 'addTranslationFolder');
|
spyOn(translationService, 'addTranslationFolder');
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(translationService.addTranslationFolder).toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
expect(translationService.addTranslationFolder).toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -130,21 +130,21 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
component.ngOnChanges({
|
component.ngOnChanges({
|
||||||
searchTerm: searchTerm
|
searchTerm: searchTerm
|
||||||
});
|
});
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.displaySearchResults).toHaveBeenCalledWith(searchTerm.currentValue);
|
expect(component.displaySearchResults).toHaveBeenCalledWith(searchTerm.currentValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear results straight away when a new search term is entered', (done) => {
|
it('should clear results straight away when a new search term is entered', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.searchTerm = 'searchTerm2';
|
component.searchTerm = 'searchTerm2';
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('table[data-automation-id="autocomplete_results"] tbody tr').length).toBe(0);
|
expect(element.querySelectorAll('table[data-automation-id="autocomplete_results"] tbody tr').length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -155,12 +155,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should display the returned search results', (done) => {
|
it('should display the returned search results', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect( element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
expect( element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
||||||
expect( element.querySelector('#result_name_0').innerHTML).toBe('<b _ngcontent-a-1="">MyDoc</b>');
|
expect( element.querySelector('#result_name_0').innerHTML).toBe('<b _ngcontent-a-1="">MyDoc</b>');
|
||||||
done();
|
done();
|
||||||
@ -172,18 +172,18 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should display the correct thumbnail for result items', (done) => {
|
it('should display the correct thumbnail for result items', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.baseComponentPath = 'http://localhost';
|
component.baseComponentPath = 'http://localhost';
|
||||||
|
|
||||||
let thumbnailService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoThumbnailService);
|
let thumbnailService = fixture.debugElement.injector.get(AlfrescoThumbnailService);
|
||||||
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('fake-type-icon.svg');
|
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('fake-type-icon.svg');
|
||||||
spyOn(thumbnailService, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
|
spyOn(thumbnailService, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(() => {
|
component.resultsEmitter.subscribe(() => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let imgEl = <any> element.querySelector('#result_row_0 img');
|
let imgEl = <any> element.querySelector('#result_row_0 img');
|
||||||
expect(imgEl).not.toBeNull();
|
expect(imgEl).not.toBeNull();
|
||||||
expect(imgEl.src).toBe('http://localhost/img/fake-type-icon.svg');
|
expect(imgEl.src).toBe('http://localhost/img/fake-type-icon.svg');
|
||||||
@ -197,12 +197,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should display no result if no result are returned', (done) => {
|
it('should display no result if no result are returned', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(noResult));
|
.and.returnValue(Promise.resolve(noResult));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -213,12 +213,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should display an error if an error is encountered running the search', (done) => {
|
it('should display an error if an error is encountered running the search', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.reject(errorJson));
|
.and.returnValue(Promise.reject(errorJson));
|
||||||
|
|
||||||
component.errorEmitter.subscribe(() => {
|
component.errorEmitter.subscribe(() => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let resultsEl = element.querySelector('[data-automation-id="autocomplete_results"]');
|
let resultsEl = element.querySelector('[data-automation-id="autocomplete_results"]');
|
||||||
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
||||||
expect(resultsEl).toBeNull();
|
expect(resultsEl).toBeNull();
|
||||||
@ -233,15 +233,15 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should clear errors straight away when a new search is performed', (done) => {
|
it('should clear errors straight away when a new search is performed', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.reject(errorJson));
|
.and.returnValue(Promise.reject(errorJson));
|
||||||
|
|
||||||
component.errorEmitter.subscribe(() => {
|
component.errorEmitter.subscribe(() => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.searchTerm = 'searchTerm2';
|
component.searchTerm = 'searchTerm2';
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
||||||
expect(errorEl).toBeNull();
|
expect(errorEl).toBeNull();
|
||||||
done();
|
done();
|
||||||
@ -253,12 +253,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should emit preview when file item clicked', (done) => {
|
it('should emit preview when file item clicked', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
(<any> element.querySelector('#result_row_0')).click();
|
(<any> element.querySelector('#result_row_0')).click();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -272,13 +272,13 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
|
|
||||||
it('should not emit preview if a non-file item is clicked', (done) => {
|
it('should not emit preview if a non-file item is clicked', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(folderResult));
|
.and.returnValue(Promise.resolve(folderResult));
|
||||||
|
|
||||||
spyOn(component.preview, 'emit');
|
spyOn(component.preview, 'emit');
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
(<any> element.querySelector('#result_row_0')).click();
|
(<any> element.querySelector('#result_row_0')).click();
|
||||||
expect(component.preview.emit).not.toHaveBeenCalled();
|
expect(component.preview.emit).not.toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
|
@ -33,7 +33,7 @@ import { AlfrescoSearchService } from '../services/alfresco-search.service';
|
|||||||
|
|
||||||
describe('AlfrescoSearchControlComponent', () => {
|
describe('AlfrescoSearchControlComponent', () => {
|
||||||
|
|
||||||
let alfrescoSearchControlComponentFixture: ComponentFixture<AlfrescoSearchControlComponent>;
|
let fixture: ComponentFixture<AlfrescoSearchControlComponent>;
|
||||||
let component: AlfrescoSearchControlComponent, element: HTMLElement;
|
let component: AlfrescoSearchControlComponent, element: HTMLElement;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@ -55,76 +55,76 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
AlfrescoSearchService
|
AlfrescoSearchService
|
||||||
]
|
]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
alfrescoSearchControlComponentFixture = TestBed.createComponent(AlfrescoSearchControlComponent);
|
fixture = TestBed.createComponent(AlfrescoSearchControlComponent);
|
||||||
component = alfrescoSearchControlComponentFixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = alfrescoSearchControlComponentFixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should setup i18n folder', () => {
|
it('should setup i18n folder', () => {
|
||||||
let translationService = alfrescoSearchControlComponentFixture.debugElement.injector.get(AlfrescoTranslationService);
|
let translationService = fixture.debugElement.injector.get(AlfrescoTranslationService);
|
||||||
spyOn(translationService, 'addTranslationFolder');
|
spyOn(translationService, 'addTranslationFolder');
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(translationService.addTranslationFolder)
|
expect(translationService.addTranslationFolder)
|
||||||
.toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
.toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit searchChange when search term input changed', (done) => {
|
it('should emit searchChange when search term input changed', (done) => {
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.searchChange.subscribe(e => {
|
fixture.componentInstance.searchChange.subscribe(e => {
|
||||||
expect(e.value).toBe('customSearchTerm');
|
expect(e.value).toBe('customSearchTerm');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.searchTerm = 'customSearchTerm';
|
fixture.componentInstance.searchTerm = 'customSearchTerm';
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit searchChange when search term changed by user', (done) => {
|
it('should emit searchChange when search term changed by user', (done) => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.searchChange.subscribe(e => {
|
fixture.componentInstance.searchChange.subscribe(e => {
|
||||||
expect(e.value).toBe('customSearchTerm211');
|
expect(e.value).toBe('customSearchTerm211');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
component.searchControl.setValue('customSearchTerm211', true);
|
component.searchControl.setValue('customSearchTerm211', true);
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Component rendering', () => {
|
describe('Component rendering', () => {
|
||||||
|
|
||||||
it('should display a text input field by default', () => {
|
it('should display a text input field by default', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('input[type="text"]').length).toBe(1);
|
expect(element.querySelectorAll('input[type="text"]').length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display a search input field when specified', () => {
|
it('should display a search input field when specified', () => {
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.inputType = 'search';
|
fixture.componentInstance.inputType = 'search';
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('input[type="search"]').length).toBe(1);
|
expect(element.querySelectorAll('input[type="search"]').length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set browser autocomplete to off by default', () => {
|
it('should set browser autocomplete to off by default', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let attr = element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete');
|
let attr = element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete');
|
||||||
expect(attr).toBe('off');
|
expect(attr).toBe('off');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set browser autocomplete to on when configured', () => {
|
it('should set browser autocomplete to on when configured', () => {
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.autocomplete = true;
|
fixture.componentInstance.autocomplete = true;
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete')).toBe('on');
|
expect(element.querySelectorAll('input[type="text"]')[0].getAttribute('autocomplete')).toBe('on');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show an expanding control by default', () => {
|
it('should show an expanding control by default', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(1);
|
expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(1);
|
||||||
expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(1);
|
expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(1);
|
||||||
expect(element.querySelectorAll('label.mdl-button--icon').length).toBe(1);
|
expect(element.querySelectorAll('label.mdl-button--icon').length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show a normal non-expanding control when configured', () => {
|
it('should show a normal non-expanding control when configured', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.expandable = false;
|
fixture.componentInstance.expandable = false;
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(0);
|
expect(element.querySelectorAll('div.mdl-textfield--expandable').length).toBe(0);
|
||||||
expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(0);
|
expect(element.querySelectorAll('div.mdl-textfield__expandable-holder').length).toBe(0);
|
||||||
expect(element.querySelectorAll('label.mdl-button--icon').length).toBe(0);
|
expect(element.querySelectorAll('label.mdl-button--icon').length).toBe(0);
|
||||||
@ -140,31 +140,31 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display a find-as-you-type control by default', () => {
|
it('should display a find-as-you-type control by default', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete).not.toBeNull();
|
expect(autocomplete).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should make find-as-you-type control hidden initially', () => {
|
it('should make find-as-you-type control hidden initially', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete.classList.contains('active')).toBe(false);
|
expect(autocomplete.classList.contains('active')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should make find-as-you-type control visible when search box has focus', () => {
|
it('should make find-as-you-type control visible when search box has focus', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
inputEl.dispatchEvent(new Event('focus'));
|
inputEl.dispatchEvent(new Event('focus'));
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete.classList.contains('active')).toBe(true);
|
expect(autocomplete.classList.contains('active')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hide find-as-you-type results when the search box loses focus', (done) => {
|
it('should hide find-as-you-type results when the search box loses focus', (done) => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
inputEl.dispatchEvent(new Event('focus'));
|
inputEl.dispatchEvent(new Event('focus'));
|
||||||
inputEl.dispatchEvent(new Event('blur'));
|
inputEl.dispatchEvent(new Event('blur'));
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete.classList.contains('active')).toBe(false);
|
expect(autocomplete.classList.contains('active')).toBe(false);
|
||||||
done();
|
done();
|
||||||
@ -172,18 +172,18 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should hide find-as-you-type results when escape key pressed', () => {
|
it('should hide find-as-you-type results when escape key pressed', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
inputEl.dispatchEvent(new Event('focus'));
|
inputEl.dispatchEvent(new Event('focus'));
|
||||||
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
key: 'Escape'
|
key: 'Escape'
|
||||||
}));
|
}));
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete.classList.contains('active')).toBe(false);
|
expect(autocomplete.classList.contains('active')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should make find-as-you-type control visible again when down arrow is pressed', () => {
|
it('should make find-as-you-type control visible again when down arrow is pressed', () => {
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
inputEl.dispatchEvent(new Event('focus'));
|
inputEl.dispatchEvent(new Event('focus'));
|
||||||
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
key: 'Escape'
|
key: 'Escape'
|
||||||
@ -191,14 +191,14 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
inputEl.dispatchEvent(new KeyboardEvent('keyup', {
|
||||||
key: 'ArrowDown'
|
key: 'ArrowDown'
|
||||||
}));
|
}));
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete.classList.contains('active')).toBe(true);
|
expect(autocomplete.classList.contains('active')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT display a find-as-you-type control when configured not to', () => {
|
it('should NOT display a find-as-you-type control when configured not to', () => {
|
||||||
alfrescoSearchControlComponentFixture.componentInstance.autocompleteEnabled = false;
|
fixture.componentInstance.autocompleteEnabled = false;
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
let autocomplete: Element = element.querySelector('alfresco-search-autocomplete');
|
||||||
expect(autocomplete).toBeNull();
|
expect(autocomplete).toBeNull();
|
||||||
});
|
});
|
||||||
@ -209,14 +209,14 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
|
|
||||||
it('should fire a search when a term has been entered', () => {
|
it('should fire a search when a term has been entered', () => {
|
||||||
spyOn(component.searchSubmit, 'emit');
|
spyOn(component.searchSubmit, 'emit');
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let formEl: HTMLElement = element.querySelector('form');
|
let formEl: HTMLElement = element.querySelector('form');
|
||||||
component.searchTerm = 'searchTerm1';
|
component.searchTerm = 'searchTerm1';
|
||||||
component.searchControl.setValue('searchTerm1', true);
|
component.searchControl.setValue('searchTerm1', true);
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
formEl.dispatchEvent(new Event('submit'));
|
formEl.dispatchEvent(new Event('submit'));
|
||||||
|
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.searchSubmit.emit).toHaveBeenCalledWith({
|
expect(component.searchSubmit.emit).toHaveBeenCalledWith({
|
||||||
'value': 'searchTerm1'
|
'value': 'searchTerm1'
|
||||||
@ -225,13 +225,13 @@ describe('AlfrescoSearchControlComponent', () => {
|
|||||||
|
|
||||||
it('should not fire a search when no term has been entered', () => {
|
it('should not fire a search when no term has been entered', () => {
|
||||||
spyOn(component.searchSubmit, 'emit');
|
spyOn(component.searchSubmit, 'emit');
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let inputEl: HTMLInputElement = <HTMLInputElement> element.querySelector('input[type="text"]');
|
let inputEl: HTMLInputElement = <HTMLInputElement> element.querySelector('input[type="text"]');
|
||||||
let formEl: HTMLElement = element.querySelector('form');
|
let formEl: HTMLElement = element.querySelector('form');
|
||||||
inputEl.value = '';
|
inputEl.value = '';
|
||||||
formEl.dispatchEvent(new Event('submit'));
|
formEl.dispatchEvent(new Event('submit'));
|
||||||
|
|
||||||
alfrescoSearchControlComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.searchSubmit.emit).not.toHaveBeenCalled();
|
expect(component.searchSubmit.emit).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,7 @@ import {
|
|||||||
|
|
||||||
describe('AlfrescoSearchComponent', () => {
|
describe('AlfrescoSearchComponent', () => {
|
||||||
|
|
||||||
let alfrescoSearchComponentFixture: ComponentFixture<AlfrescoSearchComponent>, element: HTMLElement;
|
let fixture: ComponentFixture<AlfrescoSearchComponent>, element: HTMLElement;
|
||||||
let component: AlfrescoSearchComponent;
|
let component: AlfrescoSearchComponent;
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
@ -113,9 +113,9 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
AlfrescoContentService
|
AlfrescoContentService
|
||||||
]
|
]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
alfrescoSearchComponentFixture = TestBed.createComponent(AlfrescoSearchComponent);
|
fixture = TestBed.createComponent(AlfrescoSearchComponent);
|
||||||
component = alfrescoSearchComponentFixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = alfrescoSearchComponentFixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -148,9 +148,9 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setup i18n folder', () => {
|
it('should setup i18n folder', () => {
|
||||||
let translationService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoTranslationService);
|
let translationService = fixture.debugElement.injector.get(AlfrescoTranslationService);
|
||||||
spyOn(translationService, 'addTranslationFolder');
|
spyOn(translationService, 'addTranslationFolder');
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(translationService.addTranslationFolder).toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
expect(translationService.addTranslationFolder).toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -158,12 +158,12 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should display search results when a search term is provided', (done) => {
|
it('should display search results when a search term is provided', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(searchService.getSearchNodesPromise).toHaveBeenCalled();
|
expect(searchService.getSearchNodesPromise).toHaveBeenCalled();
|
||||||
expect(element.querySelector('#result_user_0')).not.toBeNull();
|
expect(element.querySelector('#result_user_0')).not.toBeNull();
|
||||||
expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
||||||
@ -177,12 +177,12 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should display no result if no result are returned', (done) => {
|
it('should display no result if no result are returned', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(noResult));
|
.and.returnValue(Promise.resolve(noResult));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -193,12 +193,12 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should display an error if an error is encountered running the search', (done) => {
|
it('should display an error if an error is encountered running the search', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.reject(errorJson));
|
.and.returnValue(Promise.reject(errorJson));
|
||||||
|
|
||||||
component.errorEmitter.subscribe(() => {
|
component.errorEmitter.subscribe(() => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let resultsEl = element.querySelector('[data-automation-id="search_result_table"]');
|
let resultsEl = element.querySelector('[data-automation-id="search_result_table"]');
|
||||||
let errorEl = element.querySelector('[data-automation-id="search_error_message"]');
|
let errorEl = element.querySelector('[data-automation-id="search_error_message"]');
|
||||||
expect(resultsEl).toBeNull();
|
expect(resultsEl).toBeNull();
|
||||||
@ -213,12 +213,12 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should update search results when the search term input is changed', (done) => {
|
it('should update search results when the search term input is changed', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(searchService.getSearchNodesPromise).toHaveBeenCalledWith('searchTerm2');
|
expect(searchService.getSearchNodesPromise).toHaveBeenCalledWith('searchTerm2');
|
||||||
expect(element.querySelector('#result_user_0')).not.toBeNull();
|
expect(element.querySelector('#result_user_0')).not.toBeNull();
|
||||||
expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
||||||
@ -234,12 +234,12 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should emit preview when file item clicked', (done) => {
|
it('should emit preview when file item clicked', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(result));
|
.and.returnValue(Promise.resolve(result));
|
||||||
|
|
||||||
component.resultsEmitter.subscribe(() => {
|
component.resultsEmitter.subscribe(() => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
(<HTMLTableRowElement> element.querySelector('#result_row_0')).click();
|
(<HTMLTableRowElement> element.querySelector('#result_row_0')).click();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -253,13 +253,13 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
it('should not emit preview when non-file item is clicked', (done) => {
|
it('should not emit preview when non-file item is clicked', (done) => {
|
||||||
|
|
||||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||||
spyOn(searchService, 'getSearchNodesPromise')
|
spyOn(searchService, 'getSearchNodesPromise')
|
||||||
.and.returnValue(Promise.resolve(folderResult));
|
.and.returnValue(Promise.resolve(folderResult));
|
||||||
|
|
||||||
spyOn(component.preview, 'emit');
|
spyOn(component.preview, 'emit');
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
fixture.detectChanges();
|
||||||
(<HTMLTableRowElement> element.querySelector('#result_row_0')).click();
|
(<HTMLTableRowElement> element.querySelector('#result_row_0')).click();
|
||||||
expect(component.preview.emit).not.toHaveBeenCalled();
|
expect(component.preview.emit).not.toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user