mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -15,11 +15,41 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { it, describe } from '@angular/core/testing';
|
||||
import { provide } from '@angular/core';
|
||||
import {
|
||||
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
|
||||
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
import { it, describe, expect, inject, beforeEachProviders, setBaseTestProviders } from '@angular/core/testing';
|
||||
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 {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoContentService,
|
||||
AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
|
||||
describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
let searchService;
|
||||
|
||||
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
|
||||
|
||||
beforeEachProviders(() => {
|
||||
searchService = new SearchServiceMock();
|
||||
|
||||
return [
|
||||
searchService.getProviders(),
|
||||
provide(AlfrescoThumbnailService, {}),
|
||||
provide(AlfrescoTranslationService, {}),
|
||||
provide(AlfrescoSettingsService, {}),
|
||||
provide(AlfrescoAuthenticationService, {}),
|
||||
provide(AlfrescoContentService, {})
|
||||
];
|
||||
});
|
||||
|
||||
it('should setup i18n folder', () => {
|
||||
|
||||
let translation = jasmine.createSpyObj('AlfrescoTranslationService', [
|
||||
@@ -30,4 +60,96 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
|
||||
});
|
||||
|
||||
it('should display search results when a search term is provided',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(AlfrescoSearchAutocompleteComponent)
|
||||
.then((fixture) => {
|
||||
let componentInstance = fixture.componentInstance,
|
||||
searchTerm = 'customSearchTerm';
|
||||
spyOn(componentInstance, 'displaySearchResults').and.stub();
|
||||
componentInstance.searchTerm = searchTerm;
|
||||
componentInstance.ngOnChanges({
|
||||
searchTerm: searchTerm
|
||||
});
|
||||
fixture.detectChanges();
|
||||
expect(componentInstance.displaySearchResults).toHaveBeenCalledWith(searchTerm);
|
||||
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display the returned search results',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(AlfrescoSearchAutocompleteComponent)
|
||||
.then((fixture) => {
|
||||
let componentInstance = fixture.componentInstance;
|
||||
componentInstance.results = [{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
let element = fixture.nativeElement;
|
||||
expect(element.querySelectorAll('table tr').length).toBe(1);
|
||||
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit preview when file item clicked',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(AlfrescoSearchAutocompleteComponent)
|
||||
.then((fixture) => {
|
||||
let componentInstance = fixture.componentInstance;
|
||||
componentInstance.results = [{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
isFile: true
|
||||
}
|
||||
}];
|
||||
fixture.detectChanges(componentInstance.results[0]);
|
||||
componentInstance.preview.subscribe(e => {
|
||||
expect(e.value).toBe(componentInstance.results[0]);
|
||||
});
|
||||
componentInstance.onItemClick();
|
||||
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not emit preview when non-file item clicked',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(AlfrescoSearchAutocompleteComponent)
|
||||
.then((fixture) => {
|
||||
let componentInstance = fixture.componentInstance;
|
||||
componentInstance.results = [{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
isFile: true
|
||||
}
|
||||
}];
|
||||
fixture.detectChanges(componentInstance.results[0]);
|
||||
componentInstance.preview.subscribe(e => {
|
||||
expect(e.value).toBe(componentInstance.results[0]);
|
||||
});
|
||||
componentInstance.onItemClick();
|
||||
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user