[ACS-8863] Add nodeMimeType to keep proper file icon when renditions are generated (#10508)

* [ACS-8863] Add nodeMimeType to keep proper file icon when renditions are generated

* [ACS-8863] Small fix
This commit is contained in:
MichalKinas
2024-12-23 09:56:13 +01:00
committed by GitHub
parent dc7e5c2215
commit d45155bcb2
6 changed files with 44 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ import { ViewerWithCustomSidebarComponent } from './mock/adf-viewer-container-si
import { ViewerWithCustomToolbarActionsComponent } from './mock/adf-viewer-container-toolbar-actions.component.mock';
import { ViewerWithCustomToolbarComponent } from './mock/adf-viewer-container-toolbar.component.mock';
import { ViewerComponent } from './viewer.component';
import { ThumbnailService } from '@alfresco/adf-core';
@Component({
selector: 'adf-dialog-dummy',
@@ -49,6 +50,7 @@ describe('ViewerComponent', () => {
let dialog: MatDialog;
let viewUtilService: ViewUtilService;
let appConfigService: AppConfigService;
let thumbnailService: ThumbnailService;
beforeEach(() => {
TestBed.configureTestingModule({
@@ -72,6 +74,7 @@ describe('ViewerComponent', () => {
dialog = TestBed.inject(MatDialog);
viewUtilService = TestBed.inject(ViewUtilService);
appConfigService = TestBed.inject(AppConfigService);
thumbnailService = TestBed.inject(ThumbnailService);
component.fileName = 'test-file.pdf';
appConfigService.config = {
@@ -97,6 +100,27 @@ describe('ViewerComponent', () => {
expect(component.mimeType).toBe('image/png');
});
it('should set mimeTypeIconUrl when mimeType changes and no nodeMimeType is provided', () => {
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('image/png');
const mockSimpleChanges: any = { mimeType: { currentValue: 'image/png' }, nodeMimeType: undefined };
component.ngOnChanges(mockSimpleChanges);
expect(thumbnailService.getMimeTypeIcon).toHaveBeenCalledWith('image/png');
expect(component.mimeTypeIconUrl).toBe('image/png');
});
it('should set mimeTypeIconUrl when nodeMimeType changes', () => {
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('application/pdf');
const mockSimpleChanges: any = { mimeType: { currentValue: 'image/png' }, nodeMimeType: { currentValue: 'application/pdf' } };
component.ngOnChanges(mockSimpleChanges);
fixture.detectChanges();
expect(thumbnailService.getMimeTypeIcon).toHaveBeenCalledWith('application/pdf');
expect(component.mimeTypeIconUrl).toBe('application/pdf');
});
});
describe('File Name Test', () => {

View File

@@ -244,6 +244,10 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
@Input()
nodeId: string = null;
/** Original node mime type, should be provided when renditiona mime type is different. */
@Input()
nodeMimeType: string = undefined;
/**
* Enable dialog box to allow user to download the previewed file, in case the preview is not responding for a set period of time.
*/
@@ -303,7 +307,7 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
) {}
ngOnChanges(changes: SimpleChanges) {
const { blobFile, urlFile, mimeType } = changes;
const { blobFile, urlFile, mimeType, nodeMimeType } = changes;
if (blobFile?.currentValue) {
this.mimeType = blobFile.currentValue.type;
@@ -314,9 +318,13 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
this.fileName ||= this.viewUtilsService.getFilenameFromUrl(urlFile.currentValue);
}
if (mimeType?.currentValue) {
if (mimeType?.currentValue && !nodeMimeType?.currentValue) {
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(mimeType.currentValue);
}
if (nodeMimeType?.currentValue) {
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(nodeMimeType.currentValue);
}
}
ngOnInit(): void {