From 2207156f3f332be13d5695ebb1061687f2d9f115 Mon Sep 17 00:00:00 2001
From: Denys Vuika <denys.vuika@gmail.com>
Date: Wed, 21 Dec 2022 15:39:24 +0000
Subject: [PATCH] [AAE-10319] unit test fixes for content-services lib

---
 lib/content-services/karma.conf.js            |  4 +-
 .../src/lib/social/rating.component.spec.ts   |  4 +-
 .../src/lib/testing/content.testing.module.ts |  4 +-
 .../version-list.component.spec.ts            | 52 +++++++++----------
 .../version-manager/version-list.component.ts |  6 +--
 5 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/lib/content-services/karma.conf.js b/lib/content-services/karma.conf.js
index af17feb3cc..0e0e0ab18e 100644
--- a/lib/content-services/karma.conf.js
+++ b/lib/content-services/karma.conf.js
@@ -21,7 +21,7 @@ module.exports = function (config) {
                 served: true,
                 watched: false
             },
-            {pattern: 'lib/core/src/lib/assets/images/ft_ic_folder.svg', included: false, served: true, watched: false},
+            {pattern: 'lib/core/src/lib/assets/**/*.svg', included: false, served: true, watched: false},
             {pattern: 'lib/core/src/lib/i18n/**/en.json', included: false, served: true, watched: false},
             {pattern: 'lib/content-services/**/*.ts', included: false, served: true, watched: false},
             {pattern: 'lib/config/app.config.json', included: false, served: true, watched: false}
@@ -30,8 +30,8 @@ module.exports = function (config) {
         frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'],
 
         proxies: {
+            '/assets/images/': '/base/lib/core/src/lib/assets/images/',
             '/base/assets/': '/base/lib/content-services/src/lib/assets/',
-            '/base/lib/content-services/assets/images/ft_ic_folder.svg': '/base/lib/core/src/lib/assets/images/ft_ic_folder.svg',
             '/assets/': '/base/lib/content-services/src/lib/assets/',
             '/assets/adf-content-services/i18n/en.json': '/base/lib/content-services/src/lib/i18n/en.json',
             '/assets/adf-core/i18n/en.json': '/base/lib/core/src/lib/i18n/en.json',
diff --git a/lib/content-services/src/lib/social/rating.component.spec.ts b/lib/content-services/src/lib/social/rating.component.spec.ts
index 56cd082390..0ad3367d91 100644
--- a/lib/content-services/src/lib/social/rating.component.spec.ts
+++ b/lib/content-services/src/lib/social/rating.component.spec.ts
@@ -139,13 +139,13 @@ describe('Rating component', () => {
             }
         }));
 
-        const deleteSpy = spyOn(service, 'deleteRating');
+        spyOn(service, 'deleteRating').and.returnValue(of({}));
 
         component.ngOnChanges();
         fixture.detectChanges();
         const starThree: any = element.querySelector('#adf-colored-star-2');
         starThree.click();
         expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
-        expect(deleteSpy).toHaveBeenCalled();
+        expect(service.deleteRating).toHaveBeenCalled();
     });
 });
diff --git a/lib/content-services/src/lib/testing/content.testing.module.ts b/lib/content-services/src/lib/testing/content.testing.module.ts
index 6d8c67c34c..5ea41bcab4 100644
--- a/lib/content-services/src/lib/testing/content.testing.module.ts
+++ b/lib/content-services/src/lib/testing/content.testing.module.ts
@@ -33,6 +33,7 @@ import { ContentModule } from '../content.module';
 import { TranslateModule } from '@ngx-translate/core';
 import { versionCompatibilityFactory } from '../version-compatibility/version-compatibility-factory';
 import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
+import { MatIconTestingModule } from '@angular/material/icon/testing';
 
 @NgModule({
     imports: [
@@ -40,7 +41,8 @@ import { VersionCompatibilityService } from '../version-compatibility/version-co
         RouterTestingModule,
         TranslateModule,
         CoreModule,
-        ContentModule
+        ContentModule,
+        MatIconTestingModule
     ],
     providers: [
         { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
diff --git a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts
index de95b2c45d..96133904bb 100644
--- a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts
+++ b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts
@@ -63,7 +63,7 @@ describe('VersionListComponent', () => {
         component.node = { id: nodeId, allowableOperations: ['update'] } as Node;
 
         spyOn(component, 'downloadContent').and.stub();
-        spyOn(component['nodesApi'], 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: { id: 'nodeInfoId' } })));
+        spyOn(component.nodesApi, 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: { id: 'nodeInfoId' } })));
     });
 
     it('should raise confirmation dialog on delete', () => {
@@ -86,12 +86,12 @@ describe('VersionListComponent', () => {
             afterClosed: () => of(true)
         } as any);
 
-        spyOn(component['versionsApi'], 'deleteVersion').and.returnValue(Promise.resolve(true));
+        spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
 
         component.deleteVersion(versionId);
 
         expect(dialog.open).toHaveBeenCalled();
-        expect(component['versionsApi'].deleteVersion).toHaveBeenCalledWith(nodeId, versionId);
+        expect(component.versionsApi.deleteVersion).toHaveBeenCalledWith(nodeId, versionId);
     });
 
     it('should not delete version if user rejects', () => {
@@ -101,12 +101,12 @@ describe('VersionListComponent', () => {
             afterClosed: () => of(false)
         } as any);
 
-        spyOn(component['versionsApi'], 'deleteVersion').and.returnValue(Promise.resolve(true));
+        spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
 
         component.deleteVersion(versionId);
 
         expect(dialog.open).toHaveBeenCalled();
-        expect(component['versionsApi'].deleteVersion).not.toHaveBeenCalled();
+        expect(component.versionsApi.deleteVersion).not.toHaveBeenCalled();
     });
 
     it('should reload and raise deleted event', (done) => {
@@ -122,7 +122,7 @@ describe('VersionListComponent', () => {
     describe('Version history fetching', () => {
 
         it('should use loading bar', () => {
-            spyOn(component['versionsApi'], 'listVersionHistory').and
+            spyOn(component.versionsApi, 'listVersionHistory').and
                 .callFake(() => Promise.resolve({ list: { entries: versionTest } }));
 
             let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
@@ -136,18 +136,18 @@ describe('VersionListComponent', () => {
         });
 
         it('should load the versions for a given id', () => {
-            spyOn(component['versionsApi'], 'listVersionHistory').and
+            spyOn(component.versionsApi, 'listVersionHistory').and
                 .callFake(() => Promise.resolve({ list: { entries: versionTest } }));
 
             component.ngOnChanges();
             fixture.detectChanges();
 
-            expect(component['versionsApi'].listVersionHistory).toHaveBeenCalledWith(nodeId);
+            expect(component.versionsApi.listVersionHistory).toHaveBeenCalledWith(nodeId);
         });
 
         it('should show the versions after loading', (done) => {
             fixture.detectChanges();
-            spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
+            spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
                 list: {
                     entries: [
                         {
@@ -173,7 +173,7 @@ describe('VersionListComponent', () => {
         });
 
         it('should NOT show the versions comments if input property is set not to show them', (done) => {
-            spyOn(component['versionsApi'], 'listVersionHistory').and
+            spyOn(component.versionsApi, 'listVersionHistory').and
                 .callFake(() => Promise.resolve(
                     new VersionPaging({
                         list: {
@@ -208,7 +208,7 @@ describe('VersionListComponent', () => {
                     versionComment: 'test-version-comment'
                 }
             };
-            spyOn(component['versionsApi'], 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
+            spyOn(component.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
             spyOn(contentVersionService.contentApi, 'getContentUrl').and.returnValue('the/download/url');
 
             fixture.detectChanges();
@@ -232,9 +232,9 @@ describe('VersionListComponent', () => {
                     versionComment: 'test-version-comment'
                 }
             };
-            spyOn(component['versionsApi'], 'listVersionHistory').and
+            spyOn(component.versionsApi, 'listVersionHistory').and
                 .callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
-            const spyOnDownload = spyOn(component['contentApi'], 'getContentUrl').and.stub();
+            const spyOnDownload = spyOn(component.contentApi, 'getContentUrl').and.stub();
 
             component.allowDownload = false;
             fixture.detectChanges();
@@ -248,16 +248,16 @@ describe('VersionListComponent', () => {
 
         it('should restore version only when restore allowed', () => {
             component.node.allowableOperations = [];
-            spyOn(component['versionsApi'], 'revertVersion').and.stub();
+            spyOn(component.versionsApi, 'revertVersion').and.stub();
             component.restore('1');
-            expect(component['versionsApi'].revertVersion).not.toHaveBeenCalled();
+            expect(component.versionsApi.revertVersion).not.toHaveBeenCalled();
         });
 
         it('should load the versions for a given id', () => {
             fixture.detectChanges();
             component.versions = versionTest;
 
-            const spyOnRevertVersion = spyOn(component['versionsApi'], 'revertVersion').and
+            const spyOnRevertVersion = spyOn(component.versionsApi, 'revertVersion').and
                 .callFake(() => Promise.resolve(new VersionEntry(
                     { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
 
@@ -269,10 +269,10 @@ describe('VersionListComponent', () => {
         it('should get node info after restoring the node', fakeAsync(() => {
             fixture.detectChanges();
             component.versions = versionTest;
-            spyOn(component['versionsApi'], 'listVersionHistory')
+            spyOn(component.versionsApi, 'listVersionHistory')
                 .and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
 
-            spyOn(component['versionsApi'], 'revertVersion')
+            spyOn(component.versionsApi, 'revertVersion')
                 .and.callFake(() => Promise.resolve(new VersionEntry(
                 { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
 
@@ -280,16 +280,16 @@ describe('VersionListComponent', () => {
             fixture.detectChanges();
             tick();
 
-            expect(component['nodesApi'].getNode).toHaveBeenCalled();
+            expect(component.nodesApi.getNode).toHaveBeenCalled();
         }));
 
         it('should emit with node info data', fakeAsync(() => {
             fixture.detectChanges();
             component.versions = versionTest;
-            spyOn(component['versionsApi'], 'listVersionHistory')
+            spyOn(component.versionsApi, 'listVersionHistory')
                 .and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
 
-            spyOn(component['versionsApi'], 'revertVersion')
+            spyOn(component.versionsApi, 'revertVersion')
                 .and.callFake(() => Promise.resolve(new VersionEntry(
                 { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
 
@@ -306,9 +306,9 @@ describe('VersionListComponent', () => {
             fixture.detectChanges();
             component.versions = versionTest;
 
-            const spyOnListVersionHistory = spyOn(component['versionsApi'], 'listVersionHistory').and
+            const spyOnListVersionHistory = spyOn(component.versionsApi, 'listVersionHistory').and
                 .callFake(() => Promise.resolve({ list: { entries: versionTest } }));
-            spyOn(component['versionsApi'], 'revertVersion').and.callFake(() => Promise.resolve(null));
+            spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(null));
 
             component.restore(versionId);
             fixture.detectChanges();
@@ -325,7 +325,7 @@ describe('VersionListComponent', () => {
             beforeEach(() => {
                 fixture.detectChanges();
                 component.node = new Node({ id: nodeId });
-                spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
+                spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
                     list: {
                         entries: [
                             {
@@ -372,7 +372,7 @@ describe('VersionListComponent', () => {
             beforeEach(() => {
                 fixture.detectChanges();
                 component.node = { id: nodeId } as Node;
-                spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
+                spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
                     list: {
                         entries: [
                             {
@@ -420,7 +420,7 @@ describe('VersionListComponent', () => {
             beforeEach(() => {
                 fixture.detectChanges();
                 component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
-                spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
+                spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
                     list: {
                         entries: [
                             {
diff --git a/lib/content-services/src/lib/version-manager/version-list.component.ts b/lib/content-services/src/lib/version-manager/version-list.component.ts
index de45c52723..f0dc91dcb6 100644
--- a/lib/content-services/src/lib/version-manager/version-list.component.ts
+++ b/lib/content-services/src/lib/version-manager/version-list.component.ts
@@ -31,19 +31,19 @@ import { ContentVersionService } from './content-version.service';
 })
 export class VersionListComponent implements OnChanges {
 
-    _contentApi: ContentApi;
+    private _contentApi: ContentApi;
     get contentApi(): ContentApi {
         this._contentApi = this._contentApi ?? new ContentApi(this.alfrescoApi.getInstance());
         return this._contentApi;
     }
 
-    _versionsApi: VersionsApi;
+    private _versionsApi: VersionsApi;
     get versionsApi(): VersionsApi {
         this._versionsApi = this._versionsApi ?? new VersionsApi(this.alfrescoApi.getInstance());
         return this._versionsApi;
     }
 
-    _nodesApi: NodesApi;
+    private _nodesApi: NodesApi;
     get nodesApi(): NodesApi {
         this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApi.getInstance());
         return this._nodesApi;