mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -31,7 +31,7 @@ import {
|
||||
|
||||
describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
let alfrescoSearchComponentFixture: ComponentFixture<AlfrescoSearchAutocompleteComponent>, element: HTMLElement;
|
||||
let fixture: ComponentFixture<AlfrescoSearchAutocompleteComponent>, element: HTMLElement;
|
||||
let component: AlfrescoSearchAutocompleteComponent;
|
||||
|
||||
let result = {
|
||||
@@ -110,16 +110,16 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
AlfrescoSearchService
|
||||
]
|
||||
}).compileComponents().then(() => {
|
||||
alfrescoSearchComponentFixture = TestBed.createComponent(AlfrescoSearchAutocompleteComponent);
|
||||
component = alfrescoSearchComponentFixture.componentInstance;
|
||||
element = alfrescoSearchComponentFixture.nativeElement;
|
||||
fixture = TestBed.createComponent(AlfrescoSearchAutocompleteComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should setup i18n folder', () => {
|
||||
let translationService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoTranslationService);
|
||||
let translationService = fixture.debugElement.injector.get(AlfrescoTranslationService);
|
||||
spyOn(translationService, 'addTranslationFolder');
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
expect(translationService.addTranslationFolder).toHaveBeenCalledWith('node_modules/ng2-alfresco-search/dist/src');
|
||||
});
|
||||
|
||||
@@ -130,21 +130,21 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
component.ngOnChanges({
|
||||
searchTerm: searchTerm
|
||||
});
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
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);
|
||||
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||
spyOn(searchService, 'getSearchNodesPromise')
|
||||
.and.returnValue(Promise.resolve(result));
|
||||
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
component.searchTerm = 'searchTerm2';
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -155,12 +155,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
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')
|
||||
.and.returnValue(Promise.resolve(result));
|
||||
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
expect( element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
||||
expect( element.querySelector('#result_name_0').innerHTML).toBe('<b _ngcontent-a-1="">MyDoc</b>');
|
||||
done();
|
||||
@@ -172,18 +172,18 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
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')
|
||||
.and.returnValue(Promise.resolve(result));
|
||||
|
||||
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, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
|
||||
|
||||
component.resultsEmitter.subscribe(() => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let imgEl = <any> element.querySelector('#result_row_0 img');
|
||||
expect(imgEl).not.toBeNull();
|
||||
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) => {
|
||||
|
||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
||||
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||
spyOn(searchService, 'getSearchNodesPromise')
|
||||
.and.returnValue(Promise.resolve(noResult));
|
||||
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
@@ -213,12 +213,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
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')
|
||||
.and.returnValue(Promise.reject(errorJson));
|
||||
|
||||
component.errorEmitter.subscribe(() => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let resultsEl = element.querySelector('[data-automation-id="autocomplete_results"]');
|
||||
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
||||
expect(resultsEl).toBeNull();
|
||||
@@ -233,15 +233,15 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
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')
|
||||
.and.returnValue(Promise.reject(errorJson));
|
||||
|
||||
component.errorEmitter.subscribe(() => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
component.searchTerm = 'searchTerm2';
|
||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let errorEl = <any> element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
||||
expect(errorEl).toBeNull();
|
||||
done();
|
||||
@@ -253,12 +253,12 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
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')
|
||||
.and.returnValue(Promise.resolve(result));
|
||||
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
(<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) => {
|
||||
|
||||
let searchService = alfrescoSearchComponentFixture.debugElement.injector.get(AlfrescoSearchService);
|
||||
let searchService = fixture.debugElement.injector.get(AlfrescoSearchService);
|
||||
spyOn(searchService, 'getSearchNodesPromise')
|
||||
.and.returnValue(Promise.resolve(folderResult));
|
||||
|
||||
spyOn(component.preview, 'emit');
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
(<any> element.querySelector('#result_row_0')).click();
|
||||
expect(component.preview.emit).not.toHaveBeenCalled();
|
||||
done();
|
||||
|
Reference in New Issue
Block a user