mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
fix: ng2-alfresco-search
This commit is contained in:
@@ -134,11 +134,14 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
|
||||
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('fake-type-icon.svg');
|
||||
spyOn(thumbnailService, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
|
||||
|
||||
let path = 'http://localhost/fake-type-icon.svg';
|
||||
spyOn(component, 'resolveIconPath').and.returnValue(path);
|
||||
|
||||
component.resultsLoad.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
let imgEl = <any> element.querySelector('#result_row_0 img');
|
||||
expect(imgEl).not.toBeNull();
|
||||
expect(imgEl.src).toBe('../img/fake-type-icon.svg');
|
||||
expect(imgEl.src).toBe(path);
|
||||
expect(imgEl.alt).toBe('SEARCH.ICONS.FAKE_TYPE');
|
||||
done();
|
||||
});
|
||||
|
@@ -124,10 +124,25 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
|
||||
getMimeTypeIcon(node: any): string {
|
||||
if (node.entry.content && node.entry.content.mimeType) {
|
||||
let icon = this.alfrescoThumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
|
||||
return require(`./../img/${icon}`);
|
||||
return this.resolveIconPath(icon);
|
||||
}
|
||||
}
|
||||
|
||||
resolveIconPath(icon: string): string {
|
||||
let result = null;
|
||||
try {
|
||||
// webpack
|
||||
result = require(`./../img/${icon}`);
|
||||
} catch (e) {
|
||||
// system.js
|
||||
if (module && module.id) {
|
||||
let baseComponentPath = module.id.replace('/components/alfresco-search-autocomplete.component.js', '');
|
||||
result = `${baseComponentPath}/img/${icon}`;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets thumbnail message key for the given document node, which can be used to look up alt text
|
||||
* @param node Node to get URL for.
|
||||
|
@@ -91,10 +91,25 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
|
||||
getMimeTypeIcon(node: any): string {
|
||||
if (node.entry.content && node.entry.content.mimeType) {
|
||||
let icon = this._alfrescoThumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
|
||||
return require(`./../img/${icon}`);
|
||||
return this.resolveIconPath(icon);
|
||||
}
|
||||
}
|
||||
|
||||
private resolveIconPath(icon: string): string {
|
||||
let result = null;
|
||||
try {
|
||||
// webpack
|
||||
result = require(`./../img/${icon}`);
|
||||
} catch (e) {
|
||||
// system.js
|
||||
if (module && module.id) {
|
||||
let baseComponentPath = module.id.replace('/components/alfresco-search.component.js', '');
|
||||
result = `${baseComponentPath}/img/${icon}`;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets thumbnail message key for the given document node, which can be used to look up alt text
|
||||
* @param node Node to get URL for.
|
||||
|
Reference in New Issue
Block a user