mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Eugenio Romano
parent
74e918d916
commit
36ce9bce0d
@@ -208,7 +208,7 @@ describe('Metadata component', () => {
|
|||||||
await viewerPage.clickCloseButton();
|
await viewerPage.clickCloseButton();
|
||||||
contentServicesPage.waitForTableBody();
|
contentServicesPage.waitForTableBody();
|
||||||
|
|
||||||
viewerPage.viewFile(resources.Files.ADF_DOCUMENTS.PNG.file_name);
|
viewerPage.viewFile('exampleText.png');
|
||||||
viewerPage.clickInfoButton();
|
viewerPage.clickInfoButton();
|
||||||
viewerPage.checkInfoSideBarIsDisplayed();
|
viewerPage.checkInfoSideBarIsDisplayed();
|
||||||
metadataViewPage.clickOnPropertiesTab();
|
metadataViewPage.clickOnPropertiesTab();
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
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 { By } from '@angular/platform-browser';
|
||||||
import { VersionListComponent } from './version-list.component';
|
import { VersionListComponent } from './version-list.component';
|
||||||
import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||||
@@ -71,6 +71,7 @@ describe('VersionListComponent', () => {
|
|||||||
component.node = <Node> { id: nodeId, allowableOperations: ['update'] };
|
component.node = <Node> { id: nodeId, allowableOperations: ['update'] };
|
||||||
|
|
||||||
spyOn(component, 'downloadContent').and.stub();
|
spyOn(component, 'downloadContent').and.stub();
|
||||||
|
spyOn(alfrescoApiService.nodesApi, 'getNodeInfo').and.returnValue(Promise.resolve(<Node> { id: 'nodeInfoId' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise confirmation dialog on delete', () => {
|
it('should raise confirmation dialog on delete', () => {
|
||||||
@@ -285,7 +286,43 @@ describe('VersionListComponent', () => {
|
|||||||
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: '' });
|
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();
|
fixture.detectChanges();
|
||||||
component.versions = versionTest;
|
component.versions = versionTest;
|
||||||
|
|
||||||
@@ -294,12 +331,11 @@ describe('VersionListComponent', () => {
|
|||||||
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
|
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
|
||||||
|
|
||||||
component.restore(versionId);
|
component.restore(versionId);
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
|
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
|
||||||
done();
|
}));
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Actions buttons', () => {
|
describe('Actions buttons', () => {
|
||||||
|
@@ -82,7 +82,13 @@ export class VersionListComponent implements OnChanges {
|
|||||||
if (this.canUpdate()) {
|
if (this.canUpdate()) {
|
||||||
this.versionsApi
|
this.versionsApi
|
||||||
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: '' })
|
.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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,8 +17,16 @@
|
|||||||
|
|
||||||
import { DateCellComponent } from './date-cell.component';
|
import { DateCellComponent } from './date-cell.component';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
import { AlfrescoApiServiceMock, AppConfigService } from '@alfresco/adf-core';
|
||||||
|
import { Node } from '@alfresco/js-api';
|
||||||
|
|
||||||
describe('DataTableCellComponent', () => {
|
describe('DataTableCellComponent', () => {
|
||||||
|
let alfrescoApiService: AlfrescoApiServiceMock;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null));
|
||||||
|
});
|
||||||
|
|
||||||
it('should use medium format by default', () => {
|
it('should use medium format by default', () => {
|
||||||
const component = new DateCellComponent(null, null);
|
const component = new DateCellComponent(null, null);
|
||||||
expect(component.format).toBe('medium');
|
expect(component.format).toBe('medium');
|
||||||
@@ -37,4 +45,72 @@ describe('DataTableCellComponent', () => {
|
|||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
expect(component.format).toBe('longTime');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -85,10 +85,9 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
|
|||||||
this.updateValue();
|
this.updateValue();
|
||||||
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
|
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
|
||||||
if (this.row) {
|
if (this.row) {
|
||||||
const { entry } = this.row['node'];
|
if (this.row['node'].entry.id === node.id) {
|
||||||
|
this.row['node'].entry = node;
|
||||||
if (entry === node) {
|
this.row['cache'][this.column.key] = this.column.key.split('.').reduce((source, key) => source[key], node);
|
||||||
this.row['node'] = { entry };
|
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user