mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Merge pull request #892 from Alfresco/dev-wabson-890
Re-enable search service tests
This commit is contained in:
@@ -42,9 +42,11 @@ module.exports = function (config) {
|
|||||||
{pattern: 'dist/**/*.html', included: true, served: true, watched: true},
|
{pattern: 'dist/**/*.html', included: true, served: true, watched: true},
|
||||||
{pattern: 'dist/**/*.css', included: true, served: true, watched: true},
|
{pattern: 'dist/**/*.css', included: true, served: true, watched: true},
|
||||||
|
|
||||||
|
// mimetype icons
|
||||||
|
{pattern: 'dist/src/img/*.svg', included: false, served: true, watched: false},
|
||||||
|
|
||||||
// ng2-components
|
// ng2-components
|
||||||
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false },
|
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false },
|
||||||
{ pattern: 'node_modules/ng2-alfresco-search/dist/**/*.js', included: false, served: true, watched: false },
|
|
||||||
|
|
||||||
// paths to support debugging with source maps in dev tools
|
// paths to support debugging with source maps in dev tools
|
||||||
{pattern: 'src/**/*.ts', included: false, watched: false},
|
{pattern: 'src/**/*.ts', included: false, watched: false},
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export var fakeSearch = {
|
||||||
|
list: {
|
||||||
|
pagination: {
|
||||||
|
count: 1,
|
||||||
|
hasMoreItems: false,
|
||||||
|
totalItems: 1,
|
||||||
|
skipCount: 0,
|
||||||
|
maxItems: 100
|
||||||
|
},
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
id: '123',
|
||||||
|
name: 'MyDoc',
|
||||||
|
content: {
|
||||||
|
mimetype: 'text/plain'
|
||||||
|
},
|
||||||
|
createdByUser: {
|
||||||
|
displayName: 'John Doe'
|
||||||
|
},
|
||||||
|
modifiedByUser: {
|
||||||
|
displayName: 'John Doe'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export var fakeError = {
|
||||||
|
error: {
|
||||||
|
errorKey: 'Search failed',
|
||||||
|
statusCode: 400,
|
||||||
|
briefSummary: '08220082 search failed',
|
||||||
|
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||||
|
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export var fakeApi = {
|
||||||
|
core: {
|
||||||
|
searchApi: {
|
||||||
|
liveSearchNodes: (term, opts) => Promise.resolve(fakeSearch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@@ -134,24 +134,23 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
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', async(() => {
|
||||||
|
|
||||||
let searchService = fixture.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.searchTerm = 'searchTerm';
|
||||||
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''} });
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.searchTerm = 'searchTerm2';
|
component.searchTerm = 'searchTerm2';
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
||||||
fixture.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();
|
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
component.searchTerm = 'searchTerm';
|
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''} });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display the returned search results', (done) => {
|
it('should display the returned search results', (done) => {
|
||||||
|
|
||||||
@@ -231,25 +230,24 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
|||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
|
||||||
});
|
});
|
||||||
|
|
||||||
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', async(() => {
|
||||||
|
|
||||||
let searchService = fixture.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.searchTerm = 'searchTerm';
|
||||||
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.searchTerm = 'searchTerm2';
|
component.searchTerm = 'searchTerm2';
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm2', previousValue: 'searchTerm'} });
|
||||||
fixture.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();
|
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
component.searchTerm = 'searchTerm';
|
|
||||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''}});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should emit preview when file item clicked', (done) => {
|
it('should emit preview when file item clicked', (done) => {
|
||||||
|
|
||||||
|
@@ -75,8 +75,8 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
|||||||
public displaySearchResults(searchTerm) {
|
public displaySearchResults(searchTerm) {
|
||||||
if (searchTerm !== null && searchTerm !== '') {
|
if (searchTerm !== null && searchTerm !== '') {
|
||||||
this.alfrescoSearchService
|
this.alfrescoSearchService
|
||||||
.getSearchNodesPromise(searchTerm)
|
.getLiveSearchResults(searchTerm)
|
||||||
.then(
|
.subscribe(
|
||||||
results => {
|
results => {
|
||||||
this.results = results.list.entries;
|
this.results = results.list.entries;
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
|
@@ -15,79 +15,66 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { beforeEachProviders } from '@angular/core/testing';
|
|
||||||
import { AlfrescoSearchService } from './alfresco-search.service';
|
import { AlfrescoSearchService } from './alfresco-search.service';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
|
||||||
|
import { fakeApi, fakeSearch, fakeError } from '../assets/alfresco-search.service.mock';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('AlfrescoSearchService', () => {
|
describe('AlfrescoSearchService', () => {
|
||||||
|
|
||||||
let service: any;
|
let service: AlfrescoSearchService;
|
||||||
|
let authenticationService: AlfrescoAuthenticationService;
|
||||||
|
let injector: ReflectiveInjector;
|
||||||
|
|
||||||
let fakeSearch = {
|
beforeEach(() => {
|
||||||
list: {
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
pagination: {
|
|
||||||
count: 1,
|
|
||||||
hasMoreItems: false,
|
|
||||||
totalItems: 1,
|
|
||||||
skipCount: 0,
|
|
||||||
maxItems: 100
|
|
||||||
},
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
entry: {
|
|
||||||
id: '123',
|
|
||||||
name: 'MyDoc',
|
|
||||||
content: {
|
|
||||||
mimetype: 'text/plain'
|
|
||||||
},
|
|
||||||
createdByUser: {
|
|
||||||
displayName: 'John Doe'
|
|
||||||
},
|
|
||||||
modifiedByUser: {
|
|
||||||
displayName: 'John Doe'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
|
||||||
return [
|
|
||||||
AlfrescoSearchService,
|
AlfrescoSearchService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService
|
AlfrescoAuthenticationService
|
||||||
];
|
]);
|
||||||
|
service = injector.get(AlfrescoSearchService);
|
||||||
|
authenticationService = injector.get(AlfrescoAuthenticationService);
|
||||||
|
spyOn(authenticationService, 'getAlfrescoApi').and.returnValue(fakeApi);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(inject([AlfrescoSearchService], (alfrescoSearchService: AlfrescoSearchService) => {
|
it('should call search API with the correct parameters', (done) => {
|
||||||
jasmine.Ajax.install();
|
let searchTerm = 'searchTerm63688', options = {
|
||||||
service = alfrescoSearchService;
|
include: [ 'path' ],
|
||||||
}));
|
rootNodeId: '-root-',
|
||||||
|
nodeType: 'cm:content'
|
||||||
afterEach(() => {
|
};
|
||||||
jasmine.Ajax.uninstall();
|
spyOn(fakeApi.core.searchApi, 'liveSearchNodes').and.returnValue(Promise.resolve(fakeSearch));
|
||||||
});
|
service.getLiveSearchResults(searchTerm).subscribe(
|
||||||
|
() => {
|
||||||
it('should return search list', (done) => {
|
expect(fakeApi.core.searchApi.liveSearchNodes).toHaveBeenCalledWith(searchTerm, options);
|
||||||
service.getSearchNodesPromise('MyDoc').then(
|
|
||||||
(res) => {
|
|
||||||
expect(res).toBeDefined();
|
|
||||||
expect(res.list.entries[0].entry.name).toEqual('MyDoc');
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
it('should return search results returned from the API', (done) => {
|
||||||
'status': 200,
|
service.getLiveSearchResults('').subscribe(
|
||||||
contentType: 'application/json',
|
(res: any) => {
|
||||||
responseText: JSON.stringify(fakeSearch)
|
expect(res).toBeDefined();
|
||||||
});
|
expect(res).toEqual(fakeSearch);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should notify errors returned from the API', (done) => {
|
||||||
|
spyOn(fakeApi.core.searchApi, 'liveSearchNodes').and.returnValue(Promise.reject(fakeError));
|
||||||
|
service.getLiveSearchResults('').subscribe(
|
||||||
|
() => {},
|
||||||
|
(res: any) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(res).toEqual(fakeError);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
@@ -28,16 +28,6 @@ export class AlfrescoSearchService {
|
|||||||
constructor(private authService: AlfrescoAuthenticationService) {
|
constructor(private authService: AlfrescoAuthenticationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSearchNodesPromise(term: string) {
|
|
||||||
let nodeId = '-root-';
|
|
||||||
let opts = {
|
|
||||||
include: ['path'],
|
|
||||||
rootNodeId: nodeId,
|
|
||||||
nodeType: 'cm:content'
|
|
||||||
};
|
|
||||||
return this.authService.getAlfrescoApi().core.searchApi.liveSearchNodes(term, opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a search against the repository
|
* Execute a search against the repository
|
||||||
*
|
*
|
||||||
@@ -50,10 +40,17 @@ export class AlfrescoSearchService {
|
|||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getSearchNodesPromise(term: string) {
|
||||||
|
let nodeId = '-root-';
|
||||||
|
let opts = {
|
||||||
|
include: ['path'],
|
||||||
|
rootNodeId: nodeId,
|
||||||
|
nodeType: 'cm:content'
|
||||||
|
};
|
||||||
|
return this.authService.getAlfrescoApi().core.searchApi.liveSearchNodes(term, opts);
|
||||||
|
}
|
||||||
|
|
||||||
private handleError(error: any): Observable<any> {
|
private handleError(error: any): Observable<any> {
|
||||||
// in a real world app, we may send the error to some remote logging infrastructure
|
|
||||||
// instead of just logging it to the console
|
|
||||||
console.error(error);
|
|
||||||
return Observable.throw(error || 'Server error');
|
return Observable.throw(error || 'Server error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user