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-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 }}
|
||||
|
@@ -317,59 +317,18 @@ 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;
|
||||
};
|
||||
|
||||
describe('showActions', () => {
|
||||
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();
|
||||
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();
|
||||
});
|
||||
|
||||
it('should show Actions if showActions is true', (done) => {
|
||||
component.versions = versionTest;
|
||||
|
||||
component.showActions = true;
|
||||
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();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide Actions if showActions is false', (done) => {
|
||||
component.showActions = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
const menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
|
||||
|
||||
expect(menuButton).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('disabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
component.node = { id: nodeId } as Node;
|
||||
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||
list: {
|
||||
entries: [
|
||||
@@ -382,15 +341,47 @@ describe('VersionListComponent', () => {
|
||||
]
|
||||
}
|
||||
})));
|
||||
});
|
||||
|
||||
describe('showActions', () => {
|
||||
beforeEach(() => {
|
||||
component.node = new Node({ id: nodeId });
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should show Actions if showActions is true', (done) => {
|
||||
component.versions = versionTest;
|
||||
|
||||
component.showActions = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(getActionMenuButton()).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide Actions if showActions is false', (done) => {
|
||||
component.showActions = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(getActionMenuButton()).toBeUndefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('disabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.node = { id: nodeId } as Node;
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user