mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
parent
2e58481f15
commit
124da1ff0b
@ -47,7 +47,7 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
name: 'MyDoc',
|
||||
isFile : true,
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
mimeType: 'text/plain'
|
||||
},
|
||||
createdByUser: {
|
||||
displayName: 'John Doe'
|
||||
@ -61,12 +61,43 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
}
|
||||
};
|
||||
|
||||
let folderResult = {
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyFolder',
|
||||
isFile : false,
|
||||
isFolder : true,
|
||||
createdByUser: {
|
||||
displayName: 'John Doe'
|
||||
},
|
||||
modifiedByUser: {
|
||||
displayName: 'John Doe'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
let noResult = {
|
||||
list: {
|
||||
entries: []
|
||||
}
|
||||
};
|
||||
|
||||
let errorJson = {
|
||||
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'
|
||||
}
|
||||
};
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||
@ -133,10 +164,35 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should display the correct thumbnail for result items', (done) => {
|
||||
|
||||
component.baseComponentPath = 'http://localhost';
|
||||
spyOn(component.alfrescoThumbnailService, 'getMimeTypeIcon').and.returnValue('fake-type-icon.svg');
|
||||
spyOn(component.alfrescoThumbnailService, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
|
||||
|
||||
component.resultsEmitter.subscribe(() => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
let imgEl = element.querySelector('#result_row_0 img');
|
||||
expect(imgEl).not.toBeNull();
|
||||
expect(imgEl.src).toBe('http://localhost/img/fake-type-icon.svg');
|
||||
expect(imgEl.alt).toBe('SEARCH.ICONS.FAKE_TYPE');
|
||||
done();
|
||||
});
|
||||
|
||||
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||
component.ngOnChanges({searchTerm: component.searchTerm });
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: result
|
||||
});
|
||||
});
|
||||
|
||||
it('should display no result if no result are returned', (done) => {
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
expect( element.querySelector('#search_no_result')).not.toBe(null);
|
||||
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
|
||||
@ -150,6 +206,27 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should display an error if an error is encountered running the search', (done) => {
|
||||
component.errorEmitter.subscribe(() => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
let resultsEl = element.querySelector('[data-automation-id="autocomplete_results"]');
|
||||
let errorEl = element.querySelector('[data-automation-id="autocomplete_error_message"]');
|
||||
expect(resultsEl).toBeNull();
|
||||
expect(errorEl).not.toBeNull();
|
||||
expect(errorEl.innerText).toBe('SEARCH.RESULTS.ERROR');
|
||||
done();
|
||||
});
|
||||
|
||||
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||
component.ngOnChanges({searchTerm: component.searchTerm});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 500,
|
||||
contentType: 'json',
|
||||
responseText: errorJson
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit preview when file item clicked', (done) => {
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
@ -170,22 +247,23 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not emit preview when non-file item is clicked', () => {
|
||||
spyOn(component, 'onItemClick').and.stub();
|
||||
|
||||
component.ngOnChanges({searchTerm: { currentValue: 'searchTerm', previousValue: ''} });
|
||||
|
||||
component.preview.subscribe(e => {
|
||||
expect(e.value).toBe(component.results[0]);
|
||||
it('should not emit preview if a non-file item is clicked', (done) => {
|
||||
spyOn(component.preview, 'emit');
|
||||
component.resultsEmitter.subscribe(x => {
|
||||
alfrescoSearchComponentFixture.detectChanges();
|
||||
element.querySelector('#result_row_0').click();
|
||||
expect(component.preview.emit).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
|
||||
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||
component.ngOnChanges({searchTerm: component.searchTerm});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: result
|
||||
responseText: folderResult
|
||||
});
|
||||
|
||||
expect(component.onItemClick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -48,6 +48,9 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
|
||||
@Output()
|
||||
resultsEmitter = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
errorEmitter = new EventEmitter();
|
||||
|
||||
constructor(private alfrescoSearchService: AlfrescoSearchService,
|
||||
private translate: AlfrescoTranslationService,
|
||||
private alfrescoThumbnailService: AlfrescoThumbnailService) {
|
||||
@ -80,6 +83,7 @@ export class AlfrescoSearchAutocompleteComponent implements OnChanges {
|
||||
error => {
|
||||
this.results = null;
|
||||
this.errorMessage = <any>error;
|
||||
this.errorEmitter.emit(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user