mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Unit test fixes
This commit is contained in:
@@ -15,29 +15,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { provide } from '@angular/core';
|
||||
import { AlfrescoSearchService } from '../services/alfresco-search.service';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
export class SearchServiceMock {
|
||||
export class SearchServiceMock extends AlfrescoSearchService {
|
||||
|
||||
public getLiveSearchResults(term: string): Observable<any> {
|
||||
getLiveSearchResults(term: string): Observable<any> {
|
||||
if (term.length > 3) {
|
||||
return Observable.of({
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '123'
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
createdByUser: {
|
||||
displayName: 'John Doe'
|
||||
},
|
||||
modifiedByUser: {
|
||||
displayName: 'John Doe'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Observable.throw('Fake server error');
|
||||
}
|
||||
}
|
||||
|
||||
getProviders(): Array<any> {
|
||||
return [provide(AlfrescoSearchService, {useValue: this})];
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { AlfrescoSearchAutocompleteComponent } from './alfresco-search-autocomplete.component';
|
||||
import { SearchServiceMock } from './../assets/alfresco-search.service.mock';
|
||||
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
|
||||
import { AlfrescoSearchService } from '../services/alfresco-search.service';
|
||||
import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
@@ -29,13 +30,9 @@ import {
|
||||
|
||||
describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
let searchService;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
searchService = new SearchServiceMock();
|
||||
|
||||
return [
|
||||
searchService.getProviders(),
|
||||
provide(AlfrescoSearchService, {useClass: SearchServiceMock}),
|
||||
provide(AlfrescoThumbnailService, {}),
|
||||
provide(AlfrescoTranslationService, {}),
|
||||
provide(AlfrescoSettingsService, {}),
|
||||
|
@@ -27,16 +27,14 @@ import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoContentService,
|
||||
AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSearchService } from '../services/alfresco-search.service';
|
||||
|
||||
|
||||
describe('AlfrescoSearchControlComponent', () => {
|
||||
|
||||
let searchService;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
searchService = new SearchServiceMock();
|
||||
|
||||
return [
|
||||
searchService.getProviders(),
|
||||
provide(AlfrescoSearchService, {useClass: SearchServiceMock}),
|
||||
provide(AlfrescoThumbnailService, {}),
|
||||
provide(AlfrescoTranslationService, {useClass: TranslationMock}),
|
||||
provide(AlfrescoSettingsService, {}),
|
||||
|
@@ -22,8 +22,8 @@
|
||||
<tr *ngFor="let result of results; let idx = index">
|
||||
<td><img src="{{getMimeTypeIcon(result)}}" /></td>
|
||||
<td attr.data-automation-id=file_{{result.entry.name}} >{{result.entry.name}}</td>
|
||||
<td attr.data-automation-id=file_{{result.entry.name}}_{{result.entry.modifiedByUser.displayName}} >{{result.entry.modifiedByUser
|
||||
.displayName}}</td>
|
||||
<td attr.data-automation-id=file_{{result.entry.name}}_{{result.entry.modifiedByUser.displayName}}>
|
||||
{{result.entry.modifiedByUser.displayName}}</td>
|
||||
<td>{{result.entry.modifiedAt | date}}</td>
|
||||
</tr>
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import { AlfrescoSearchComponent } from './alfresco-search.component';
|
||||
import { SearchServiceMock } from './../assets/alfresco-search.service.mock';
|
||||
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
|
||||
import { TranslationMock } from './../assets/translation.service.mock';
|
||||
import { AlfrescoSearchService } from '../services/alfresco-search.service';
|
||||
import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
@@ -31,18 +32,15 @@ import {
|
||||
|
||||
describe('AlfrescoSearchComponent', () => {
|
||||
|
||||
let searchService;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
searchService = new SearchServiceMock();
|
||||
|
||||
return [
|
||||
searchService.getProviders(),
|
||||
provide(AlfrescoThumbnailService, {}),
|
||||
provide(AlfrescoTranslationService, {useClass: TranslationMock}),
|
||||
provide(AlfrescoSettingsService, {}),
|
||||
provide(AlfrescoAuthenticationService, {}),
|
||||
provide(AlfrescoContentService, {})
|
||||
{ provide: AlfrescoSearchService, useClass: SearchServiceMock },
|
||||
{ provide: AlfrescoThumbnailService },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
{ provide: AlfrescoSettingsService },
|
||||
{ provide: AlfrescoAuthenticationService },
|
||||
{ provide: AlfrescoContentService }
|
||||
];
|
||||
});
|
||||
|
||||
@@ -94,19 +92,13 @@ describe('AlfrescoSearchComponent', () => {
|
||||
it('should display the returned search results',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.overrideProviders(AlfrescoSearchComponent, [
|
||||
{ provide: AlfrescoSearchService, useClass: SearchServiceMock }
|
||||
])
|
||||
.createAsync(AlfrescoSearchComponent)
|
||||
.then((fixture) => {
|
||||
let componentInstance = fixture.componentInstance;
|
||||
componentInstance.results = [{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
componentInstance.searchTerm = '<term>';
|
||||
componentInstance.ngOnChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@@ -20,8 +20,7 @@ import { Observable } from 'rxjs/Rx';
|
||||
|
||||
import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoContentService
|
||||
AlfrescoAuthenticationService
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
@@ -33,8 +32,7 @@ declare let AlfrescoApi: any;
|
||||
export class AlfrescoSearchService {
|
||||
|
||||
constructor(private settings: AlfrescoSettingsService,
|
||||
private authService: AlfrescoAuthenticationService,
|
||||
private contentService: AlfrescoContentService) {
|
||||
private authService: AlfrescoAuthenticationService) {
|
||||
}
|
||||
|
||||
private getAlfrescoClient() {
|
||||
|
Reference in New Issue
Block a user