[ADF-2561] View comments on previous versions (#3137)

* [ADF-2561] View comments on previous versions

add input property to enable/disable viewing version comments

* [ADF-2561] add more tests
This commit is contained in:
Suzana Dirla 2018-04-04 14:33:15 +03:00 committed by Denys Vuika
parent 3a7751fec9
commit eb0b0fa5aa
8 changed files with 173 additions and 16 deletions

View File

@ -17,6 +17,7 @@ Displays the version history of a node in a Version Manager component
| Name | Type | Default value | Description |
| ---- | ---- | ------------- | ----------- |
| id | `string` | | ID of the node whose version history you want to display. |
| showComments | `boolean` | true | Set this to false if version comments should not be displayed. |
## Details

View File

@ -22,9 +22,10 @@ Displays the version history of a node with the ability to upload a new version.
### Properties
| Name | Type | Description |
| ---- | ---- | ----------- |
| node | [MinimalNodeEntryEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md) | The node you want to manage the version history of. |
| Name | Type | Default value | Description |
| ---- | ---- | --- | ----------- |
| node | [MinimalNodeEntryEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md) | |The node you want to manage the version history of. |
| showComments | `boolean` | true | Set this to false if version comments should not be displayed. |
### Events

View File

@ -6,7 +6,7 @@
<span class="adf-version-list-item-version">{{version.entry.id}}</span> -
<span class="adf-version-list-item-date">{{version.entry.modifiedAt | date}}</span>
</p>
<p mat-line class="adf-version-list-item-comment">{{version.entry.versionComment}}</p>
<p mat-line class="adf-version-list-item-comment" *ngIf="showComments">{{version.entry.versionComment}}</p>
<mat-menu #versionMenu="matMenu" yPosition="below" xPosition="before">
<button mat-menu-item (click)="restore(version.entry.id)"> Restore </button>

View File

@ -52,6 +52,10 @@ describe('VersionListComponent', () => {
describe('Version history fetching', () => {
it('should use loading bar', () => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
expect(loadingProgressBar).toBeNull();
@ -64,7 +68,8 @@ describe('VersionListComponent', () => {
it('should load the versions for a given id', () => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callThrough();
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
component.ngOnChanges();
fixture.detectChanges();
@ -72,15 +77,15 @@ describe('VersionListComponent', () => {
expect(alfrescoApiService.versionsApi.listVersionHistory).toHaveBeenCalledWith(nodeId);
});
it('should show the versions after loading', () => {
it('should show the versions after loading', async(() => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
return Promise.resolve([
return Promise.resolve({ list: { entries: [
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
}
]);
]}});
});
component.ngOnChanges();
@ -95,7 +100,35 @@ describe('VersionListComponent', () => {
expect(versionIdText).toBe('1.0');
expect(versionComment).toBe('test-version-comment');
});
}));
it('should NOT show the versions comments if input property is set not to show them', async(() => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve(
{
list: {
entries: [
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
}
]
}
}
));
component.showComments = false;
fixture.detectChanges();
component.ngOnChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
expect(versionCommentEl).toBeNull();
});
}));
});
describe('Version restoring', () => {
@ -103,24 +136,29 @@ describe('VersionListComponent', () => {
it('should load the versions for a given id', () => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callThrough();
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
const spyOnRevertVersion = spyOn(alfrescoApiService.versionsApi, 'revertVersion').and
.callFake(() => Promise.resolve(
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }}));
component.restore(versionId);
expect(alfrescoApiService.versionsApi.revertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: ''});
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: ''});
});
it('should reload the version list after a version restore', () => {
it('should reload the version list after a version restore', async(() => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callThrough();
const spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
component.restore(versionId);
fixture.whenStable().then(() => {
expect(alfrescoApiService.versionsApi.listVersionHistory).toHaveBeenCalledTimes(1);
});
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
});
}));
});
});

View File

@ -38,6 +38,9 @@ export class VersionListComponent implements OnChanges {
@Input()
id: string;
@Input()
showComments: boolean = true;
constructor(private alfrescoApi: AlfrescoApiService) {
this.versionsApi = this.alfrescoApi.versionsApi;
}

View File

@ -2,5 +2,5 @@
<adf-version-upload [node]="node" (success)="onUploadSuccess($event)" (error)="onUploadError($event)"></adf-version-upload>
</div>
<div class="adf-version-list-container">
<adf-version-list #versionList [id]="node.id"></adf-version-list>
<adf-version-list #versionList [id]="node.id" [showComments]="showComments"></adf-version-list>
</div>

View File

@ -0,0 +1,111 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { VersionManagerComponent } from './version-manager.component';
import { VersionListComponent } from './version-list.component';
describe('VersionManagerComponent', () => {
let component: VersionManagerComponent;
let fixture: ComponentFixture<VersionManagerComponent>;
let spyOnListVersionHistory: jasmine.Spy;
const expectedComment = 'test-version-comment';
const node: MinimalNodeEntryEntity = {
id: '1234',
name: 'TEST-NODE',
isFile: true
};
const versionEntry = {
entry: {
id: '1.0',
name: node.name,
versionComment: expectedComment
}
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
VersionManagerComponent, VersionListComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(VersionManagerComponent);
component = fixture.componentInstance;
component.node = node;
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }}));
});
it('should load the versions for a given node', () => {
fixture.detectChanges();
expect(spyOnListVersionHistory).toHaveBeenCalledWith(node.id);
});
it('should display comments for versions when not configured otherwise', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
expect(versionCommentEl).not.toBeNull();
expect(versionCommentEl.nativeElement.innerText).toBe(expectedComment);
});
}));
it('should not display comments for versions when configured not to show them', async(() => {
component.showComments = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
expect(versionCommentEl).toBeNull();
});
}));
it('should emit success event upon successful upload of a new version', () => {
fixture.detectChanges();
const emittedData = { value: { entry: node }};
component.uploadSuccess.subscribe(event => {
expect(event).toBe(emittedData);
});
component.onUploadSuccess(emittedData);
});
it('should emit error event upon failure to upload a new version', () => {
fixture.detectChanges();
const errorEvent = new CustomEvent('error');
component.uploadError.subscribe(event => {
expect(event).toBe(errorEvent);
});
component.onUploadError(errorEvent);
});
});

View File

@ -30,6 +30,9 @@ export class VersionManagerComponent {
@Input()
node: MinimalNodeEntryEntity;
@Input()
showComments: boolean = true;
@Output()
uploadSuccess: EventEmitter<any> = new EventEmitter();