mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5797] Disable restore action for the latest version of file (#8827)
* ACS-5797 Hide restore action for the latest version of file * ACS-5797 Removed duplications * ACS-5797 Fix for e2e * ACS-5797 Disable restore button for latest version
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<mat-list class="adf-version-list" *ngIf="!isLoading; else loading_template">
|
<mat-list class="adf-version-list" *ngIf="!isLoading; else loading_template">
|
||||||
<mat-list-item *ngFor="let version of versions; let idx = index">
|
<mat-list-item *ngFor="let version of versions; let idx = index; let latestVersion = first">
|
||||||
<mat-icon mat-list-icon>insert_drive_file</mat-icon>
|
<mat-icon mat-list-icon>insert_drive_file</mat-icon>
|
||||||
<p mat-line class="adf-version-list-item-name" [id]="'adf-version-list-item-name-' + version.entry.id" >{{version.entry.name}}</p>
|
<p mat-line class="adf-version-list-item-name" [id]="'adf-version-list-item-name-' + version.entry.id" >{{version.entry.name}}</p>
|
||||||
<p mat-line>
|
<p mat-line>
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<button
|
<button
|
||||||
[id]="'adf-version-list-action-restore-'+version.entry.id"
|
[id]="'adf-version-list-action-restore-'+version.entry.id"
|
||||||
[disabled]="!canUpdate()"
|
[disabled]="!canUpdate() || latestVersion"
|
||||||
mat-menu-item
|
mat-menu-item
|
||||||
(click)="restore(version.entry.id)">
|
(click)="restore(version.entry.id)">
|
||||||
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
|
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
|
||||||
|
@@ -317,22 +317,35 @@ describe('VersionListComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Actions buttons', () => {
|
describe('Actions buttons', () => {
|
||||||
|
const getActionMenuButton = (version = '1.0'): HTMLButtonElement => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
return fixture.debugElement.query(By.css(`[id="adf-version-list-action-menu-button-${version}"]`))?.nativeElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRestoreButton = (version = '1.0'): HTMLButtonElement => {
|
||||||
|
getActionMenuButton(version).click();
|
||||||
|
return fixture.debugElement.query(By.css(`[id="adf-version-list-action-restore-${version}"]`))?.nativeElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||||
|
list: {
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
entry: { name: 'test-file-two', id: '1.1', versionComment: 'test-version-comment' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
|
||||||
describe('showActions', () => {
|
describe('showActions', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
|
||||||
component.node = new Node({ id: nodeId });
|
component.node = new Node({ id: nodeId });
|
||||||
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
|
||||||
list: {
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
|
|
||||||
component.ngOnChanges();
|
component.ngOnChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -343,10 +356,7 @@ describe('VersionListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
expect(getActionMenuButton()).toBeDefined();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
|
|
||||||
|
|
||||||
expect(menuButton).not.toBeNull();
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -356,10 +366,7 @@ describe('VersionListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
expect(getActionMenuButton()).toBeUndefined();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
|
|
||||||
|
|
||||||
expect(menuButton).toBeNull();
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -368,29 +375,13 @@ describe('VersionListComponent', () => {
|
|||||||
describe('disabled', () => {
|
describe('disabled', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
|
||||||
component.node = { id: nodeId } as Node;
|
component.node = { id: nodeId } as Node;
|
||||||
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
|
||||||
list: {
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
entry: { name: 'test-file-two', id: '1.1', versionComment: 'test-version-comment' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
|
|
||||||
component.ngOnChanges();
|
component.ngOnChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable delete action if is not allowed', (done) => {
|
it('should disable delete action if is not allowed', (done) => {
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
getActionMenuButton('1.1').click();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
|
|
||||||
menuButton.click();
|
|
||||||
|
|
||||||
const deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
|
const deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
|
||||||
|
|
||||||
@@ -401,13 +392,14 @@ describe('VersionListComponent', () => {
|
|||||||
|
|
||||||
it('should disable restore action if is not allowed', (done) => {
|
it('should disable restore action if is not allowed', (done) => {
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
expect(getRestoreButton().disabled).toBeTrue();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
|
done();
|
||||||
menuButton.click();
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const restoreButton: any = document.querySelector('[id="adf-version-list-action-restore-1.1"]');
|
it('should disable restore action for the latest version', (done) => {
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(restoreButton.disabled).toBe(true);
|
expect(getRestoreButton('1.1').disabled).toBeTrue();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -416,29 +408,13 @@ describe('VersionListComponent', () => {
|
|||||||
describe('enabled', () => {
|
describe('enabled', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
|
||||||
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
|
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
|
||||||
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
|
||||||
list: {
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
entry: { name: 'test-file-name', id: '1.1', versionComment: 'test-version-comment' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
|
|
||||||
component.ngOnChanges();
|
component.ngOnChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should enable delete action if is allowed', (done) => {
|
it('should enable delete action if is allowed', (done) => {
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
getActionMenuButton('1.1').click();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
|
|
||||||
menuButton.click();
|
|
||||||
|
|
||||||
const deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
|
const deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
|
||||||
|
|
||||||
@@ -449,13 +425,7 @@ describe('VersionListComponent', () => {
|
|||||||
|
|
||||||
it('should enable restore action if is allowed', (done) => {
|
it('should enable restore action if is allowed', (done) => {
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
expect(getRestoreButton().disabled).toBeFalse();
|
||||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
|
|
||||||
menuButton.click();
|
|
||||||
|
|
||||||
const restoreButton: any = document.querySelector('[id="adf-version-list-action-restore-1.1"]');
|
|
||||||
|
|
||||||
expect(restoreButton.disabled).toBe(false);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user