mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-4423] VIEWER - when closing the upload dialog the filename changes to "Unknown" (#7024)
* fix blob type instead of image * set new crop * improve test * removed onchanges watcher
This commit is contained in:
@@ -31,6 +31,8 @@ import { CoreTestingModule } from '../../testing/core.testing.module';
|
|||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { UploadService } from '../../services/upload.service';
|
||||||
|
import { FileModel } from '../../models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-viewer-container-toolbar',
|
selector: 'adf-viewer-container-toolbar',
|
||||||
@@ -135,6 +137,7 @@ describe('ViewerComponent', () => {
|
|||||||
let alfrescoApiService: AlfrescoApiService;
|
let alfrescoApiService: AlfrescoApiService;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
let dialog: MatDialog;
|
let dialog: MatDialog;
|
||||||
|
let uploadService: UploadService;
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -168,6 +171,7 @@ describe('ViewerComponent', () => {
|
|||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
|
uploadService = TestBed.inject(UploadService);
|
||||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
dialog = TestBed.inject(MatDialog);
|
dialog = TestBed.inject(MatDialog);
|
||||||
});
|
});
|
||||||
@@ -962,25 +966,40 @@ describe('ViewerComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update version when emitted by image-viewer and user has update permissions', () => {
|
it('should update version when emitted by image-viewer and user has update permissions', () => {
|
||||||
|
spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => {});
|
||||||
|
spyOn(uploadService, 'addToQueue');
|
||||||
component.readOnly = false;
|
component.readOnly = false;
|
||||||
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'txt' } } });
|
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'img/png' } } });
|
||||||
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||||
const fakeBlob = new Blob([data], { type: 'image/png' });
|
const fakeBlob = new Blob([data], { type: 'image/png' });
|
||||||
|
const newImageFile: File = new File([fakeBlob], component?.nodeEntry?.entry?.name, { type: component?.nodeEntry?.entry?.content?.mimeType });
|
||||||
|
const newFile = new FileModel(
|
||||||
|
newImageFile,
|
||||||
|
{
|
||||||
|
majorVersion: false,
|
||||||
|
newVersion: true,
|
||||||
|
parentId: component?.nodeEntry?.entry?.parentId,
|
||||||
|
nodeType: component?.nodeEntry?.entry?.content?.mimeType
|
||||||
|
},
|
||||||
|
component.nodeEntry.entry?.id
|
||||||
|
);
|
||||||
component.onSubmitFile(fakeBlob);
|
component.onSubmitFile(fakeBlob);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.blobFile).toEqual(fakeBlob);
|
expect(uploadService.addToQueue).toHaveBeenCalledWith(...[newFile]);
|
||||||
|
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not update version when emitted by image-viewer and user doesn`t have update permissions', () => {
|
it('should not update version when emitted by image-viewer and user doesn`t have update permissions', () => {
|
||||||
|
spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => {});
|
||||||
component.readOnly = true;
|
component.readOnly = true;
|
||||||
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'txt' } } });
|
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'img/png' } } });
|
||||||
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||||
const fakeBlob = new Blob([data], { type: 'image/png' });
|
const fakeBlob = new Blob([data], { type: 'image/png' });
|
||||||
component.onSubmitFile(fakeBlob);
|
component.onSubmitFile(fakeBlob);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.blobFile).toEqual(undefined);
|
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -694,8 +694,8 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubmitFile(newImageBlob: Blob) {
|
onSubmitFile(newImageBlob: Blob) {
|
||||||
const newImageFile: File = new File([newImageBlob], this?.nodeEntry?.entry?.name, { type: this?.nodeEntry?.entry?.content?.mimeType });
|
|
||||||
if (this?.nodeEntry?.entry?.id && !this.readOnly) {
|
if (this?.nodeEntry?.entry?.id && !this.readOnly) {
|
||||||
|
const newImageFile: File = new File([newImageBlob], this?.nodeEntry?.entry?.name, { type: this?.nodeEntry?.entry?.content?.mimeType });
|
||||||
const newFile = new FileModel(
|
const newFile = new FileModel(
|
||||||
newImageFile,
|
newImageFile,
|
||||||
{
|
{
|
||||||
@@ -706,7 +706,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
},
|
},
|
||||||
this?.nodeEntry?.entry?.id
|
this?.nodeEntry?.entry?.id
|
||||||
);
|
);
|
||||||
this.blobFile = newImageBlob;
|
|
||||||
this.uploadService.addToQueue(...[newFile]);
|
this.uploadService.addToQueue(...[newFile]);
|
||||||
this.uploadService.uploadFilesInTheQueue();
|
this.uploadService.uploadFilesInTheQueue();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user