mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Unit tests for document list
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
it,
|
||||
describe,
|
||||
expect,
|
||||
beforeEach
|
||||
} from '@angular/core/testing';
|
||||
import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoContentService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { FileNode } from '../assets/document-library.model.mock';
|
||||
import { AlfrescoService } from './alfresco.service';
|
||||
|
||||
// TODO: rename to DocumentListService
|
||||
describe('AlfrescoService', () => {
|
||||
|
||||
let service: AlfrescoService;
|
||||
let settingsService: AlfrescoSettingsService;
|
||||
let authService: AlfrescoAuthenticationService;
|
||||
let contentService: AlfrescoContentService;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
settingsService = new AlfrescoSettingsService();
|
||||
authService = new AlfrescoAuthenticationService(settingsService);
|
||||
contentService = new AlfrescoContentService(settingsService, authService);
|
||||
service = new AlfrescoService(settingsService, authService, contentService);
|
||||
});
|
||||
|
||||
it('should require node to get thumbnail url', () => {
|
||||
expect(service.getDocumentThumbnailUrl(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('should require content service to get thumbnail url', () => {
|
||||
service = new AlfrescoService(settingsService, authService, null);
|
||||
let file = new FileNode();
|
||||
expect(service.getDocumentThumbnailUrl(file)).toBeNull();
|
||||
});
|
||||
|
||||
it('should resolve thumbnail url via content service', () => {
|
||||
let url = 'http://<address>';
|
||||
spyOn(contentService, 'getDocumentThumbnailUrl').and.returnValue(url);
|
||||
|
||||
let file = new FileNode();
|
||||
let thumbnailUrl = service.getDocumentThumbnailUrl(file);
|
||||
|
||||
expect(thumbnailUrl).toBe(url);
|
||||
expect(contentService.getDocumentThumbnailUrl).toHaveBeenCalledWith(file);
|
||||
});
|
||||
|
||||
it('should resolve fallback icon for mime type', () => {
|
||||
let icon = service.getMimeTypeIcon('image/png');
|
||||
expect(icon).toBe(service.mimeTypeIcons['image/png']);
|
||||
});
|
||||
|
||||
it('should resolve default icon for mime type', () => {
|
||||
expect(service.getMimeTypeIcon(null)).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
||||
expect(service.getMimeTypeIcon('')).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
||||
expect(service.getMimeTypeIcon('missing/type')).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
||||
});
|
||||
|
||||
});
|
@@ -34,6 +34,8 @@ declare let AlfrescoApi: any;
|
||||
@Injectable()
|
||||
export class AlfrescoService {
|
||||
|
||||
static DEFAULT_MIME_TYPE_ICON: string = 'ft_ic_miscellaneous.svg';
|
||||
|
||||
mimeTypeIcons: any = {
|
||||
'image/png': 'ft_ic_raster_image.svg',
|
||||
'image/jpeg': 'ft_ic_raster_image.svg',
|
||||
@@ -106,16 +108,19 @@ export class AlfrescoService {
|
||||
|
||||
/**
|
||||
* Get thumbnail URL for the given document node.
|
||||
* @param document Node to get URL for.
|
||||
* @param node Node to get URL for.
|
||||
* @returns {string} URL address.
|
||||
*/
|
||||
getDocumentThumbnailUrl(document: MinimalNodeEntity) {
|
||||
return this.contentService.getDocumentThumbnailUrl(document);
|
||||
getDocumentThumbnailUrl(node: MinimalNodeEntity) {
|
||||
if (node && this.contentService) {
|
||||
return this.contentService.getDocumentThumbnailUrl(node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getMimeTypeIcon(mimeType: string): string {
|
||||
let icon = this.mimeTypeIcons[mimeType];
|
||||
return icon || 'ft_ic_miscellaneous.svg';
|
||||
return icon || AlfrescoService.DEFAULT_MIME_TYPE_ICON;
|
||||
}
|
||||
|
||||
private handleError(error: Response) {
|
||||
|
Reference in New Issue
Block a user