mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-24660] version list action cannot be disabled using app conf (#10308)
* MNT-24660 Added possibility to hide and show viewing of versions when calling openUploadNewVersionDialog function * MNT-24660 Unit tests * MNT-24660 Allow to set allowVersionDelete and showActions by new version uploader service * MNT-24660 Unit tests and documentation * MNT-24660 Reformated documentation table * MNT-24660 Fixed sonar issues * MNT-24660 Fix sonar and additional fixes
This commit is contained in:
@@ -25,7 +25,10 @@ export interface NewVersionUploaderDialogData {
|
||||
currentVersion?: Version;
|
||||
showVersionsOnly?: boolean;
|
||||
showComments?: boolean;
|
||||
showActions?: boolean;
|
||||
allowDownload?: boolean;
|
||||
allowViewVersions?: boolean;
|
||||
allowVersionDelete?: boolean;
|
||||
}
|
||||
|
||||
export type NewVersionUploaderData = VersionManagerUploadData | ViewVersion | RefreshData;
|
||||
|
@@ -19,7 +19,10 @@
|
||||
<adf-version-list
|
||||
[node]="data.node"
|
||||
[showComments]="data.showComments"
|
||||
[showActions]="data.showActions"
|
||||
[allowDownload]="data.allowDownload"
|
||||
[allowViewVersions]="data.allowViewVersions"
|
||||
[allowVersionDelete]="data.allowVersionDelete"
|
||||
(deleted)="refresh($event)"
|
||||
(restored)="refresh($event)"
|
||||
(viewVersion)="onViewingVersion($event)"
|
||||
|
@@ -66,6 +66,7 @@
|
||||
|
||||
.adf-version-list-element {
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ import { mockFile, mockNode } from '../mock';
|
||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||
import { NewVersionUploaderDataAction } from './models';
|
||||
import { NewVersionUploaderDialogComponent } from './new-version-uploader.dialog';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { VersionListComponent } from '../version-manager/version-list.component';
|
||||
|
||||
describe('NewVersionUploaderDialog', () => {
|
||||
let component: NewVersionUploaderDialogComponent;
|
||||
@@ -138,6 +140,8 @@ describe('NewVersionUploaderDialog', () => {
|
||||
describe('Manage Versions', () => {
|
||||
const expectedManageVersionsTitle = 'ADF-NEW-VERSION-UPLOADER.DIALOG_LIST.TITLE';
|
||||
|
||||
const getVersionListComponent = (): VersionListComponent => fixture.debugElement.query(By.css(cssSelectors.adfVersionList)).componentInstance;
|
||||
|
||||
it('should display adf version list if showVersionsOnly is passed as true from parent component', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
fixture.detectChanges();
|
||||
@@ -182,5 +186,53 @@ describe('NewVersionUploaderDialog', () => {
|
||||
const matDialogTitle = nativeElement.querySelector(cssSelectors.title);
|
||||
expect(matDialogTitle.innerHTML).toEqual('TEST_TITLE');
|
||||
});
|
||||
|
||||
it('should have assigned allowViewVersions to true if allowViewVersions from data is true', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.allowViewVersions = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().allowViewVersions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowViewVersions to false if allowViewVersions from data is false', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.allowViewVersions = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().allowViewVersions).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned showActions to true if showActions from data is true', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.showActions = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().showActions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned showActions to false if showActions from data is false', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.showActions = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().showActions).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned allowVersionDelete to true if allowVersionDelete from data is true', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.allowVersionDelete = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().allowVersionDelete).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowVersionDelete to false if allowVersionDelete from data is false', () => {
|
||||
component.data.showVersionsOnly = true;
|
||||
component.data.allowVersionDelete = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(getVersionListComponent().allowVersionDelete).toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -31,6 +31,7 @@ import {
|
||||
} from './models';
|
||||
import { NewVersionUploaderDialogComponent } from './new-version-uploader.dialog';
|
||||
import { NewVersionUploaderService } from './new-version-uploader.service';
|
||||
import { Version, VersionPaging } from '@alfresco/js-api';
|
||||
|
||||
@Component({
|
||||
template: ''
|
||||
@@ -75,208 +76,245 @@ describe('NewVersionUploaderService', () => {
|
||||
});
|
||||
|
||||
describe('openUploadNewVersionDialog', () => {
|
||||
describe('Mat Dialog configuration', () => {
|
||||
let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData;
|
||||
beforeEach(() => {
|
||||
spyOn(service.versionsApi, 'listVersionHistory').and.returnValue(
|
||||
Promise.resolve({
|
||||
list: { entries: [{ entry: '2' }] }
|
||||
} as any)
|
||||
);
|
||||
mockNewVersionUploaderDialogData = {
|
||||
node: mockNode,
|
||||
let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData;
|
||||
let expectedConfig: MatDialogConfig<NewVersionUploaderDialogData>;
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(service.versionsApi, 'listVersionHistory').and.returnValue(
|
||||
Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '2'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
} as VersionPaging)
|
||||
);
|
||||
mockNewVersionUploaderDialogData = {
|
||||
node: mockNode,
|
||||
file: mockFile,
|
||||
showComments: true,
|
||||
allowDownload: true
|
||||
};
|
||||
expectedConfig = {
|
||||
data: {
|
||||
file: mockFile,
|
||||
showComments: true,
|
||||
allowDownload: true
|
||||
};
|
||||
});
|
||||
|
||||
it('Should open dialog with default configuration', fakeAsync(() => {
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, {
|
||||
data: {
|
||||
file: mockFile,
|
||||
node: mockNode,
|
||||
currentVersion: '2',
|
||||
showComments: true,
|
||||
allowDownload: true,
|
||||
showVersionsOnly: undefined
|
||||
},
|
||||
panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'],
|
||||
width: '630px'
|
||||
} as any);
|
||||
}));
|
||||
|
||||
it('Should override default dialog panelClass', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {
|
||||
panelClass: 'adf-custom-class',
|
||||
width: '500px'
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, {
|
||||
data: {
|
||||
file: mockFile,
|
||||
node: mockNode,
|
||||
currentVersion: '2',
|
||||
showComments: true,
|
||||
allowDownload: true,
|
||||
showVersionsOnly: undefined
|
||||
},
|
||||
panelClass: 'adf-custom-class',
|
||||
width: '500px'
|
||||
} as any);
|
||||
}));
|
||||
|
||||
it('Should set dialog height', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {
|
||||
height: '600px'
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, {
|
||||
data: {
|
||||
file: mockFile,
|
||||
node: mockNode,
|
||||
currentVersion: '2',
|
||||
showComments: true,
|
||||
allowDownload: true,
|
||||
showVersionsOnly: undefined
|
||||
},
|
||||
panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'],
|
||||
width: '630px',
|
||||
height: '600px'
|
||||
} as any);
|
||||
}));
|
||||
|
||||
it('Should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, {
|
||||
data: {
|
||||
file: mockFile,
|
||||
node: mockNode,
|
||||
currentVersion: '2',
|
||||
showComments: true,
|
||||
allowDownload: true,
|
||||
showVersionsOnly: undefined
|
||||
},
|
||||
panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'],
|
||||
width: '630px'
|
||||
} as any);
|
||||
}));
|
||||
|
||||
it('Should dialog add list css class if showVersionsOnly is true', fakeAsync(() => {
|
||||
const mockNewVersionUploaderDialogDataWithVersionsOnly = {
|
||||
node: mockNode,
|
||||
file: mockFile,
|
||||
showVersionsOnly: true,
|
||||
currentVersion: {
|
||||
id: '2'
|
||||
} as Version,
|
||||
showComments: true,
|
||||
allowDownload: true
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, {
|
||||
data: {
|
||||
file: mockFile,
|
||||
node: mockNode,
|
||||
currentVersion: '2',
|
||||
showComments: true,
|
||||
allowDownload: true,
|
||||
showVersionsOnly: true
|
||||
},
|
||||
panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list'],
|
||||
width: '630px'
|
||||
} as any);
|
||||
}));
|
||||
allowDownload: true,
|
||||
showVersionsOnly: undefined,
|
||||
allowViewVersions: true,
|
||||
allowVersionDelete: true,
|
||||
showActions: true
|
||||
},
|
||||
panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'],
|
||||
width: '630px'
|
||||
};
|
||||
});
|
||||
|
||||
describe('Subscribe events from Dialog', () => {
|
||||
let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData;
|
||||
it('should open dialog with default configuration', fakeAsync(() => {
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(service.versionsApi, 'listVersionHistory').and.returnValue(
|
||||
Promise.resolve({
|
||||
list: { entries: [{ entry: '2' }] }
|
||||
}) as any
|
||||
);
|
||||
mockNewVersionUploaderDialogData = {
|
||||
node: mockNode,
|
||||
file: mockFile
|
||||
};
|
||||
it('should override default dialog panelClass', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {
|
||||
panelClass: 'adf-custom-class',
|
||||
width: '500px'
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expectedConfig.panelClass = 'adf-custom-class';
|
||||
expectedConfig.width = '500px';
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
}));
|
||||
|
||||
it('should set dialog height', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {
|
||||
height: '600px'
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expectedConfig.height = '600px';
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
}));
|
||||
|
||||
it('should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => {
|
||||
const mockDialogConfiguration: MatDialogConfig = {};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
|
||||
tick();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
}));
|
||||
|
||||
it('should dialog add list css class if showVersionsOnly is true', fakeAsync(() => {
|
||||
const mockNewVersionUploaderDialogDataWithVersionsOnly = {
|
||||
node: mockNode,
|
||||
file: mockFile,
|
||||
showVersionsOnly: true,
|
||||
showComments: true,
|
||||
allowDownload: true
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise();
|
||||
tick();
|
||||
expectedConfig.data.showVersionsOnly = true;
|
||||
expectedConfig.panelClass = ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list'];
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
}));
|
||||
|
||||
it('should open dialog with correct configuration when allowViewVersions is true', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.allowViewVersions = true;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return Refresh action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<RefreshData>({
|
||||
action: NewVersionUploaderDataAction.refresh,
|
||||
node: mockNode
|
||||
}),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual({ action: NewVersionUploaderDataAction.refresh, node: mockNode });
|
||||
done();
|
||||
});
|
||||
it('should open dialog with correct configuration when allowViewVersions is false', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.allowViewVersions = false;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expectedConfig.data.allowViewVersions = false;
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return Upload action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<VersionManagerUploadData>(mockNewVersionUploaderData),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual(mockNewVersionUploaderData);
|
||||
done();
|
||||
});
|
||||
it('should open dialog with correct configuration when allowVersionDelete is true', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.allowVersionDelete = true;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return View Version action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<ViewVersion>({
|
||||
action: NewVersionUploaderDataAction.view,
|
||||
versionId: '2'
|
||||
}),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual({ action: NewVersionUploaderDataAction.view, versionId: '2' });
|
||||
done();
|
||||
});
|
||||
it('should open dialog with correct configuration when allowVersionDelete is false', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.allowVersionDelete = false;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expectedConfig.data.allowVersionDelete = false;
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return upload error', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new Subject(),
|
||||
uploadError: new BehaviorSubject<any>({ value: 'Upload error' })
|
||||
};
|
||||
spyOnDialogOpen.and.returnValue(dialogRefSpyObj);
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(
|
||||
() => {
|
||||
fail('An error should have been thrown');
|
||||
},
|
||||
(error) => {
|
||||
expect(error).toEqual({ value: 'Upload error' });
|
||||
done();
|
||||
}
|
||||
);
|
||||
it('should open dialog with correct configuration when showActions is true', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.showActions = true;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should focus element indicated by passed selector after closing modal', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<VersionManagerUploadData>(mockNewVersionUploaderData);
|
||||
const afterClosed$ = new BehaviorSubject<void>(undefined);
|
||||
dialogRefSpyObj.afterClosed = () => afterClosed$;
|
||||
const elementToFocusSelector = 'button';
|
||||
const elementToFocus = document.createElement(elementToFocusSelector);
|
||||
spyOn(elementToFocus, 'focus').and.callFake(() => {
|
||||
expect(elementToFocus.focus).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
spyOn(document, 'querySelector').and.returnValue(elementToFocus);
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, undefined, elementToFocusSelector).subscribe();
|
||||
it('should open dialog with correct configuration when showActions is false', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<NewVersionUploaderData>(mockNewVersionUploaderData);
|
||||
mockNewVersionUploaderDialogData.showActions = false;
|
||||
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => {
|
||||
expectedConfig.data.showActions = false;
|
||||
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subscribe events from Dialog', () => {
|
||||
let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData;
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(service.versionsApi, 'listVersionHistory').and.returnValue(
|
||||
Promise.resolve({
|
||||
list: { entries: [{ entry: '2' }] }
|
||||
}) as any
|
||||
);
|
||||
mockNewVersionUploaderDialogData = {
|
||||
node: mockNode,
|
||||
file: mockFile
|
||||
};
|
||||
});
|
||||
|
||||
it('Should return Refresh action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<RefreshData>({
|
||||
action: NewVersionUploaderDataAction.refresh,
|
||||
node: mockNode
|
||||
}),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual({ action: NewVersionUploaderDataAction.refresh, node: mockNode });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return Upload action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<VersionManagerUploadData>(mockNewVersionUploaderData),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual(mockNewVersionUploaderData);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return View Version action', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new BehaviorSubject<ViewVersion>({
|
||||
action: NewVersionUploaderDataAction.view,
|
||||
versionId: '2'
|
||||
}),
|
||||
uploadError: new Subject()
|
||||
};
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => {
|
||||
expect(res).toEqual({ action: NewVersionUploaderDataAction.view, versionId: '2' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return upload error', (done) => {
|
||||
dialogRefSpyObj.componentInstance = {
|
||||
dialogAction: new Subject(),
|
||||
uploadError: new BehaviorSubject<any>({ value: 'Upload error' })
|
||||
};
|
||||
spyOnDialogOpen.and.returnValue(dialogRefSpyObj);
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(
|
||||
() => {
|
||||
fail('An error should have been thrown');
|
||||
},
|
||||
(error) => {
|
||||
expect(error).toEqual({ value: 'Upload error' });
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should focus element indicated by passed selector after closing modal', (done) => {
|
||||
dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject<VersionManagerUploadData>(mockNewVersionUploaderData);
|
||||
const afterClosed$ = new BehaviorSubject<void>(undefined);
|
||||
dialogRefSpyObj.afterClosed = () => afterClosed$;
|
||||
const elementToFocusSelector = 'button';
|
||||
const elementToFocus = document.createElement(elementToFocusSelector);
|
||||
spyOn(elementToFocus, 'focus').and.callFake(() => {
|
||||
expect(elementToFocus.focus).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
spyOn(document, 'querySelector').and.returnValue(elementToFocus);
|
||||
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, undefined, elementToFocusSelector).subscribe();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -62,7 +62,17 @@ export class NewVersionUploaderService {
|
||||
const dialogRef = this.dialog.open<NewVersionUploaderDialogComponent, NewVersionUploaderDialogData>(
|
||||
NewVersionUploaderDialogComponent,
|
||||
{
|
||||
data: { file, node, currentVersion: versionPaging.list.entries[0].entry, showComments, allowDownload, showVersionsOnly },
|
||||
data: {
|
||||
file,
|
||||
node,
|
||||
currentVersion: versionPaging.list.entries[0].entry,
|
||||
showComments,
|
||||
allowDownload,
|
||||
showVersionsOnly,
|
||||
allowViewVersions: data.allowViewVersions ?? true,
|
||||
allowVersionDelete: data.allowVersionDelete ?? true,
|
||||
showActions: data.showActions ?? true
|
||||
},
|
||||
panelClass: this.composePanelClass(showVersionsOnly),
|
||||
width: '630px',
|
||||
...(config && Object.keys(config).length > 0 && config)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<mat-progress-bar *ngIf="isLoading" data-automation-id="version-history-loading-bar" mode="indeterminate"
|
||||
color="accent"></mat-progress-bar>
|
||||
<mat-list class="adf-version-list adf-version-list-element" [hidden]="isLoading">
|
||||
<cdk-virtual-scroll-viewport #viewport itemSize="88" class="adf-version-list-viewport">
|
||||
<cdk-virtual-scroll-viewport #viewport itemSize="88" class="adf-version-list-viewport" [minBufferPx]="440" [maxBufferPx]="528">
|
||||
<mat-list-item class="adf-version-list-item"
|
||||
*cdkVirtualFor="let version of versionsDataSource; let idx = index; let latestVersion = first">
|
||||
<mat-icon class="adf-version-list-icon" matListItemIcon>insert_drive_file</mat-icon>
|
||||
@@ -50,6 +50,7 @@
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
|
||||
</button>
|
||||
<button
|
||||
*ngIf="allowVersionDelete"
|
||||
[disabled]="!canDelete()"
|
||||
[id]="'adf-version-list-action-delete-' + version.entry.id"
|
||||
(click)="deleteVersion(version.entry.id)"
|
||||
|
@@ -25,6 +25,7 @@ import { Node, NodeEntry, VersionEntry, Version } from '@alfresco/js-api';
|
||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||
import { ContentVersionService } from './content-version.service';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { CdkFixedSizeVirtualScroll } from '@angular/cdk/scrolling';
|
||||
|
||||
describe('VersionListComponent', () => {
|
||||
let component: VersionListComponent;
|
||||
@@ -257,6 +258,14 @@ describe('VersionListComponent', () => {
|
||||
});
|
||||
|
||||
describe('Actions buttons', () => {
|
||||
const testDeleteButtonVisibility = (done: DoneFn, visible = true) => {
|
||||
fixture.whenStable().then(() => {
|
||||
getActionMenuButton('1.1').click();
|
||||
expect(getDeleteButton() !== null).toBe(visible);
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
||||
const getActionMenuButton = (version = '1.0'): HTMLButtonElement => {
|
||||
fixture.detectChanges();
|
||||
return fixture.debugElement.query(By.css(`[id="adf-version-list-action-menu-button-${version}"]`))?.nativeElement;
|
||||
@@ -267,6 +276,8 @@ describe('VersionListComponent', () => {
|
||||
return fixture.debugElement.query(By.css(`[id="adf-version-list-action-restore-${version}"]`))?.nativeElement;
|
||||
};
|
||||
|
||||
const getDeleteButton = (version = '1.1') => fixture.debugElement.query(By.css(`[id="adf-version-list-action-delete-${version}"]`));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
versionTest[1].entry.id = '1.1';
|
||||
@@ -355,5 +366,45 @@ describe('VersionListComponent', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete action', () => {
|
||||
beforeEach(() => {
|
||||
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
|
||||
});
|
||||
|
||||
it('should show delete action by default', (done) => {
|
||||
fixture.detectChanges();
|
||||
testDeleteButtonVisibility(done);
|
||||
});
|
||||
|
||||
it('should show delete action if allowVersionDelete is true', (done) => {
|
||||
component.allowVersionDelete = true;
|
||||
fixture.detectChanges();
|
||||
testDeleteButtonVisibility(done);
|
||||
});
|
||||
|
||||
it('should hide delete action if allowVersionDelete is false', (done) => {
|
||||
component.allowVersionDelete = false;
|
||||
fixture.detectChanges();
|
||||
testDeleteButtonVisibility(done, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Virtual list viewport', () => {
|
||||
let virtualListViewport: CdkFixedSizeVirtualScroll;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
virtualListViewport = fixture.debugElement.query(By.directive(CdkFixedSizeVirtualScroll)).injector.get(CdkFixedSizeVirtualScroll);
|
||||
});
|
||||
|
||||
it('should have assigned correct minBufferPx', () => {
|
||||
expect(virtualListViewport.minBufferPx).toBe(440);
|
||||
});
|
||||
|
||||
it('should have assigned correct maxBufferPx', () => {
|
||||
expect(virtualListViewport.maxBufferPx).toBe(528);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -113,6 +113,10 @@ export class VersionListComponent implements OnChanges, OnInit, OnDestroy {
|
||||
@Input()
|
||||
showActions = true;
|
||||
|
||||
/** Enable/disable deletion of version */
|
||||
@Input()
|
||||
allowVersionDelete = true;
|
||||
|
||||
/** Emitted when a version is restored */
|
||||
@Output()
|
||||
restored = new EventEmitter<Node>();
|
||||
|
@@ -22,6 +22,7 @@
|
||||
<div>
|
||||
<button mat-raised-button
|
||||
id="adf-show-version-upload-button"
|
||||
class="adf-version-manager-upload-button"
|
||||
(click)="toggleNewVersion()" color="primary"
|
||||
*ngIf="uploadState ==='close'">{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.ADD' | translate }}
|
||||
</button>
|
||||
@@ -32,6 +33,9 @@
|
||||
[node]="node"
|
||||
[allowDownload]="allowDownload"
|
||||
[showComments]="showComments"
|
||||
[showActions]="showActions"
|
||||
[allowViewVersions]="allowViewVersions"
|
||||
[allowVersionDelete]="allowVersionDelete"
|
||||
(deleted)="refresh($event)"
|
||||
(restored)="refresh($event)"
|
||||
(viewVersion)="onViewVersion($event)">
|
||||
|
@@ -41,6 +41,15 @@ adf-version-manager {
|
||||
|
||||
.adf-version-list-table {
|
||||
width: 100%;
|
||||
|
||||
.adf-version-manager-upload-button {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
adf-version-list {
|
||||
display: flex;
|
||||
height: 538px;
|
||||
}
|
||||
}
|
||||
|
||||
.adf-version-upload-table {
|
||||
|
@@ -118,4 +118,106 @@ describe('VersionManagerComponent', () => {
|
||||
expect(component.uploadState).toEqual('open');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Version list', () => {
|
||||
it('should have assigned showActions to true by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showActions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned showActions to true if true is passed to showActions for component', () => {
|
||||
component.showActions = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showActions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned showActions to false if false is passed to showActions for component', () => {
|
||||
component.showActions = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showActions).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned allowViewVersions to true by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowViewVersions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowViewVersions to true if true is passed to allowViewVersions for component', () => {
|
||||
component.allowViewVersions = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowViewVersions).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowViewVersions to false if false is passed to allowViewVersions for component', () => {
|
||||
component.allowViewVersions = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowViewVersions).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned allowVersionDelete to true by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowVersionDelete).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowVersionDelete to true if true is passed to allowVersionDelete for component', () => {
|
||||
component.allowVersionDelete = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowVersionDelete).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowVersionDelete to false if false is passed to allowVersionDelete for component', () => {
|
||||
component.allowVersionDelete = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowVersionDelete).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned showComments to true by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showComments).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned showComments to true if true is passed to showComments for component', () => {
|
||||
component.showComments = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showComments).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned showComments to false if false is passed to showComments for component', () => {
|
||||
component.showComments = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showComments).toBeFalse();
|
||||
});
|
||||
|
||||
it('should have assigned allowDownload to true by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.showComments).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowDownload to true if true is passed to allowDownload for component', () => {
|
||||
component.allowDownload = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowDownload).toBeTrue();
|
||||
});
|
||||
|
||||
it('should have assigned allowDownload to false if false is passed to allowDownload for component', () => {
|
||||
component.allowDownload = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.versionListComponent.allowDownload).toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -65,6 +65,18 @@ export class VersionManagerComponent implements OnInit {
|
||||
@Input()
|
||||
allowDownload = true;
|
||||
|
||||
/** Toggles showing/hiding of version actions. */
|
||||
@Input()
|
||||
showActions = true;
|
||||
|
||||
/** Enable/disable viewing versions of the current node. */
|
||||
@Input()
|
||||
allowViewVersions = true;
|
||||
|
||||
/** Enable/disable deletion of version */
|
||||
@Input()
|
||||
allowVersionDelete = true;
|
||||
|
||||
/** Emitted when a file is uploaded successfully. */
|
||||
@Output()
|
||||
uploadSuccess = new EventEmitter<Node>();
|
||||
|
Reference in New Issue
Block a user