From eb0b0fa5aa3fb8e1389e55a4e05c3a9941ef88ca Mon Sep 17 00:00:00 2001 From: Suzana Dirla Date: Wed, 4 Apr 2018 14:33:15 +0300 Subject: [PATCH] [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 --- .../version-list.component.md | 1 + .../version-manager.component.md | 7 +- .../version-list.component.html | 2 +- .../version-list.component.spec.ts | 60 ++++++++-- .../version-manager/version-list.component.ts | 3 + .../version-manager.component.html | 2 +- .../version-manager.component.spec.ts | 111 ++++++++++++++++++ .../version-manager.component.ts | 3 + 8 files changed, 173 insertions(+), 16 deletions(-) create mode 100644 lib/content-services/version-manager/version-manager.component.spec.ts diff --git a/docs/content-services/version-list.component.md b/docs/content-services/version-list.component.md index d540ef5ffe..9115c61bbb 100644 --- a/docs/content-services/version-list.component.md +++ b/docs/content-services/version-list.component.md @@ -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 diff --git a/docs/content-services/version-manager.component.md b/docs/content-services/version-manager.component.md index 67b8a8ae26..e947bcb7a5 100644 --- a/docs/content-services/version-manager.component.md +++ b/docs/content-services/version-manager.component.md @@ -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 diff --git a/lib/content-services/version-manager/version-list.component.html b/lib/content-services/version-manager/version-list.component.html index 15a8bda858..f826cb79b6 100644 --- a/lib/content-services/version-manager/version-list.component.html +++ b/lib/content-services/version-manager/version-list.component.html @@ -6,7 +6,7 @@ {{version.entry.id}} - {{version.entry.modifiedAt | date}}

-

{{version.entry.versionComment}}

+

{{version.entry.versionComment}}

diff --git a/lib/content-services/version-manager/version-list.component.spec.ts b/lib/content-services/version-manager/version-list.component.spec.ts index 6a5565a21d..baabd8a21a 100644 --- a/lib/content-services/version-manager/version-list.component.spec.ts +++ b/lib/content-services/version-manager/version-list.component.spec.ts @@ -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); }); - }); + })); }); }); diff --git a/lib/content-services/version-manager/version-list.component.ts b/lib/content-services/version-manager/version-list.component.ts index 15f0119bbf..c16c7eaffe 100644 --- a/lib/content-services/version-manager/version-list.component.ts +++ b/lib/content-services/version-manager/version-list.component.ts @@ -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; } diff --git a/lib/content-services/version-manager/version-manager.component.html b/lib/content-services/version-manager/version-manager.component.html index 4d8ee3781b..db98c4c494 100644 --- a/lib/content-services/version-manager/version-manager.component.html +++ b/lib/content-services/version-manager/version-manager.component.html @@ -2,5 +2,5 @@
- +
diff --git a/lib/content-services/version-manager/version-manager.component.spec.ts b/lib/content-services/version-manager/version-manager.component.spec.ts new file mode 100644 index 0000000000..4ef60c87da --- /dev/null +++ b/lib/content-services/version-manager/version-manager.component.spec.ts @@ -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; + 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); + }); +}); diff --git a/lib/content-services/version-manager/version-manager.component.ts b/lib/content-services/version-manager/version-manager.component.ts index 85e6868cbe..881a21635c 100644 --- a/lib/content-services/version-manager/version-manager.component.ts +++ b/lib/content-services/version-manager/version-manager.component.ts @@ -30,6 +30,9 @@ export class VersionManagerComponent { @Input() node: MinimalNodeEntryEntity; + @Input() + showComments: boolean = true; + @Output() uploadSuccess: EventEmitter = new EventEmitter();