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