[ADF-4400] Versioning - restore does not update the document list (#4605)

* emit NodeInfo data on restore

* update row data and cache on node update event

* tests

* fix metadatat e2e
This commit is contained in:
Cilibiu Bogdan
2019-04-16 12:59:37 +03:00
committed by Eugenio Romano
parent 74e918d916
commit 36ce9bce0d
5 changed files with 130 additions and 13 deletions

View File

@@ -208,7 +208,7 @@ describe('Metadata component', () => {
await viewerPage.clickCloseButton();
contentServicesPage.waitForTableBody();
viewerPage.viewFile(resources.Files.ADF_DOCUMENTS.PNG.file_name);
viewerPage.viewFile('exampleText.png');
viewerPage.clickInfoButton();
viewerPage.checkInfoSideBarIsDisplayed();
metadataViewPage.clickOnPropertiesTab();

View File

@@ -16,7 +16,7 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { VersionListComponent } from './version-list.component';
import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock } from '@alfresco/adf-core';
@@ -71,6 +71,7 @@ describe('VersionListComponent', () => {
component.node = <Node> { id: nodeId, allowableOperations: ['update'] };
spyOn(component, 'downloadContent').and.stub();
spyOn(alfrescoApiService.nodesApi, 'getNodeInfo').and.returnValue(Promise.resolve(<Node> { id: 'nodeInfoId' }));
});
it('should raise confirmation dialog on delete', () => {
@@ -285,7 +286,43 @@ describe('VersionListComponent', () => {
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: '' });
});
it('should reload the version list after a version restore', (done) => {
it('should get node info after restoring the node', fakeAsync(() => {
fixture.detectChanges();
component.versions = versionTest;
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory')
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
spyOn(alfrescoApiService.versionsApi, 'revertVersion')
.and.callFake(() => Promise.resolve(new VersionEntry(
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
component.restore(versionId);
fixture.detectChanges();
tick();
expect(alfrescoApiService.nodesApi.getNodeInfo).toHaveBeenCalled();
}));
it('should emit with node info data', fakeAsync(() => {
fixture.detectChanges();
component.versions = versionTest;
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory')
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
spyOn(alfrescoApiService.versionsApi, 'revertVersion')
.and.callFake(() => Promise.resolve(new VersionEntry(
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
spyOn(component.restored, 'emit');
component.restore(versionId);
fixture.detectChanges();
tick();
expect(component.restored.emit).toHaveBeenCalledWith(<Node> { id: 'nodeInfoId' });
}));
it('should reload the version list after a version restore', fakeAsync(() => {
fixture.detectChanges();
component.versions = versionTest;
@@ -294,12 +331,11 @@ describe('VersionListComponent', () => {
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
component.restore(versionId);
fixture.detectChanges();
tick();
fixture.whenStable().then(() => {
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
done();
});
});
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
}));
});
describe('Actions buttons', () => {

View File

@@ -82,7 +82,13 @@ export class VersionListComponent implements OnChanges {
if (this.canUpdate()) {
this.versionsApi
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: '' })
.then(() => this.onVersionRestored(this.node));
.then(() =>
this.alfrescoApi.nodesApi.getNodeInfo(
this.node.id,
{ include: ['permissions', 'path', 'isFavorite', 'allowableOperations'] }
)
)
.then((node) => this.onVersionRestored(node));
}
}

View File

@@ -17,8 +17,16 @@
import { DateCellComponent } from './date-cell.component';
import { Subject } from 'rxjs';
import { AlfrescoApiServiceMock, AppConfigService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
describe('DataTableCellComponent', () => {
let alfrescoApiService: AlfrescoApiServiceMock;
beforeEach(() => {
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null));
});
it('should use medium format by default', () => {
const component = new DateCellComponent(null, null);
expect(component.format).toBe('medium');
@@ -37,4 +45,72 @@ describe('DataTableCellComponent', () => {
component.ngOnInit();
expect(component.format).toBe('longTime');
});
it('should update cell data on alfrescoApiService.nodeUpdated event', () => {
const component = new DateCellComponent(
null,
alfrescoApiService
);
component.column = {
key: 'name',
type: 'text'
};
component.row = <any> {
cache: {
name: 'some-name'
},
node: {
entry: {
id: 'id',
name: 'test-name'
}
}
};
component.ngOnInit();
alfrescoApiService.nodeUpdated.next(<Node> {
id: 'id',
name: 'updated-name'
});
expect(component.row['node'].entry.name).toBe('updated-name');
expect(component.row['cache'].name).toBe('updated-name');
});
it('not should update cell data if ids don`t match', () => {
const component = new DateCellComponent(
null,
alfrescoApiService
);
component.column = {
key: 'name',
type: 'text'
};
component.row = <any> {
cache: {
name: 'some-name'
},
node: {
entry: {
id: 'some-id',
name: 'test-name'
}
}
};
component.ngOnInit();
alfrescoApiService.nodeUpdated.next(<Node> {
id: 'id',
name: 'updated-name'
});
expect(component.row['node'].entry.name).not.toBe('updated-name');
expect(component.row['cache'].name).not.toBe('updated-name');
});
});

View File

@@ -85,10 +85,9 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
this.updateValue();
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
if (this.row) {
const { entry } = this.row['node'];
if (entry === node) {
this.row['node'] = { entry };
if (this.row['node'].entry.id === node.id) {
this.row['node'].entry = node;
this.row['cache'][this.column.key] = this.column.key.split('.').reduce((source, key) => source[key], node);
this.updateValue();
}
}