[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:
AleksanderSklorz
2023-08-18 00:44:18 +02:00
committed by GitHub
parent 03b93721ab
commit 40adcfec2d
2 changed files with 39 additions and 69 deletions

View File

@@ -1,5 +1,5 @@
<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>
<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>
@@ -22,7 +22,7 @@
</ng-container>
<button
[id]="'adf-version-list-action-restore-'+version.entry.id"
[disabled]="!canUpdate()"
[disabled]="!canUpdate() || latestVersion"
mat-menu-item
(click)="restore(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}

View File

@@ -317,22 +317,35 @@ describe('VersionListComponent', () => {
});
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', () => {
beforeEach(() => {
fixture.detectChanges();
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();
});
@@ -343,10 +356,7 @@ describe('VersionListComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
expect(menuButton).not.toBeNull();
expect(getActionMenuButton()).toBeDefined();
done();
});
});
@@ -356,10 +366,7 @@ describe('VersionListComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
expect(menuButton).toBeNull();
expect(getActionMenuButton()).toBeUndefined();
done();
});
});
@@ -368,29 +375,13 @@ describe('VersionListComponent', () => {
describe('disabled', () => {
beforeEach(() => {
fixture.detectChanges();
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();
});
it('should disable delete action if is not allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
getActionMenuButton('1.1').click();
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) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
expect(getRestoreButton().disabled).toBeTrue();
done();
});
});
const restoreButton: any = document.querySelector('[id="adf-version-list-action-restore-1.1"]');
expect(restoreButton.disabled).toBe(true);
it('should disable restore action for the latest version', (done) => {
fixture.whenStable().then(() => {
expect(getRestoreButton('1.1').disabled).toBeTrue();
done();
});
});
@@ -416,29 +408,13 @@ describe('VersionListComponent', () => {
describe('enabled', () => {
beforeEach(() => {
fixture.detectChanges();
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();
});
it('should enable delete action if is allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
getActionMenuButton('1.1').click();
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) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
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);
expect(getRestoreButton().disabled).toBeFalse();
done();
});
});