mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
[ADF-1918] added new search api service to search component (#2667)
* [ADF-1918] added new search api service to search component * [ADF-1918] fixed close panel on empty search word * [ADF-1918] added documentation for search changes * [ADF-1918] fixed closing of subscription on destroy
This commit is contained in:
@@ -16,27 +16,40 @@
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SearchService } from '@alfresco/adf-core';
|
||||
import { SearchApiService } from '@alfresco/adf-core';
|
||||
import { QueryBody } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { SearchModule } from '../../index';
|
||||
import { differentResult, result, SimpleSearchTestComponent } from '../../mock';
|
||||
import { differentResult, folderResult, result, SimpleSearchTestComponent } from '../../mock';
|
||||
|
||||
function fakeNodeResultSearch(searchNode: QueryBody): Observable<any> {
|
||||
if (searchNode.query.query === 'FAKE_SEARCH_EXMPL') {
|
||||
return Observable.of(differentResult);
|
||||
}
|
||||
if (searchNode.filterQueries.length === 1 &&
|
||||
searchNode.filterQueries[0].query === "TYPE:'cm:folder'") {
|
||||
return Observable.of(folderResult);
|
||||
}
|
||||
return Observable.of(result);
|
||||
}
|
||||
|
||||
describe('SearchComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<SimpleSearchTestComponent>, element: HTMLElement;
|
||||
let component: SimpleSearchTestComponent;
|
||||
let searchService: SearchService;
|
||||
let searchService: SearchApiService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SearchModule
|
||||
],
|
||||
declarations: [ SimpleSearchTestComponent ]
|
||||
declarations: [SimpleSearchTestComponent]
|
||||
}).compileComponents().then(() => {
|
||||
fixture = TestBed.createComponent(SimpleSearchTestComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
searchService = TestBed.get(SearchService);
|
||||
searchService = TestBed.get(SearchApiService);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -47,8 +60,8 @@ describe('SearchComponent', () => {
|
||||
});
|
||||
|
||||
it('should clear results straight away when a new search term is entered', async(() => {
|
||||
spyOn(searchService, 'getQueryNodesPromise')
|
||||
.and.returnValues(Promise.resolve(result), Promise.resolve(differentResult));
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValues(Observable.of(result), Observable.of(differentResult));
|
||||
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
@@ -67,8 +80,8 @@ describe('SearchComponent', () => {
|
||||
}));
|
||||
|
||||
it('should display the returned search results', async(() => {
|
||||
spyOn(searchService, 'getQueryNodesPromise')
|
||||
.and.returnValue(Promise.resolve(result));
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValue(Observable.of(result));
|
||||
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
@@ -80,8 +93,8 @@ describe('SearchComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit error event when search call fail', async(() => {
|
||||
spyOn(searchService, 'getQueryNodesPromise')
|
||||
.and.returnValue(Promise.reject({ status: 402 }));
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValue(Observable.fromPromise(Promise.reject({ status: 402 })));
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
@@ -92,8 +105,8 @@ describe('SearchComponent', () => {
|
||||
}));
|
||||
|
||||
it('should be able to hide the result panel', async(() => {
|
||||
spyOn(searchService, 'getQueryNodesPromise')
|
||||
.and.returnValues(Promise.resolve(result), Promise.resolve(differentResult));
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValues(Observable.of(result), Observable.of(differentResult));
|
||||
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
@@ -111,4 +124,70 @@ describe('SearchComponent', () => {
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('search node', () => {
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should perform a search based on the query node given', async(() => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
|
||||
let fakeSearchNode: QueryBody = {
|
||||
query: {
|
||||
query: ''
|
||||
},
|
||||
filterQueries: [
|
||||
{ 'query': "TYPE:'cm:folder'" }
|
||||
]
|
||||
};
|
||||
component.setSearchNodeTo(fakeSearchNode);
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let optionShowed = element.querySelectorAll('#autocomplete-search-result-list > li').length;
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('MyFolder');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a search with a defaultNode if no searchnode is given', async(() => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
|
||||
component.setSearchWordTo('searchTerm');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let optionShowed = element.querySelectorAll('#autocomplete-search-result-list > li').length;
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('MyDoc');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a search with the searchNode given', async(() => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
|
||||
let fakeSearchNode: QueryBody = {
|
||||
query: {
|
||||
query: 'FAKE_SEARCH_EXMPL'
|
||||
},
|
||||
filterQueries: [
|
||||
{ 'query': "TYPE:'cm:folder'" }
|
||||
]
|
||||
};
|
||||
component.setSearchNodeTo(fakeSearchNode);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let optionShowed = element.querySelectorAll('#autocomplete-search-result-list > li').length;
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('TEST_DOC');
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user