From 54c4d577cbac677f6e1a1fdb955c9be2bc216074 Mon Sep 17 00:00:00 2001 From: Mykyta Maliarchuk Date: Fri, 25 Aug 2023 15:49:51 +0200 Subject: [PATCH 1/2] [ACS-5563] fixed incorrect initial loading of security marks --- .../components/files/files.component.spec.ts | 25 +++++++++++++++++-- .../lib/components/files/files.component.ts | 5 +++- .../services/app.extension.service.spec.ts | 23 ++++++++++------- .../src/lib/services/app.extension.service.ts | 6 ++--- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/projects/aca-content/src/lib/components/files/files.component.spec.ts b/projects/aca-content/src/lib/components/files/files.component.spec.ts index 167048c1ab..89ef6d7441 100644 --- a/projects/aca-content/src/lib/components/files/files.component.spec.ts +++ b/projects/aca-content/src/lib/components/files/files.component.spec.ts @@ -29,7 +29,7 @@ import { DocumentListService, FilterSearch, PathElementEntity, UploadService } f import { NodeActionsService } from '../../services/node-actions.service'; import { FilesComponent } from './files.component'; import { AppTestingModule } from '../../testing/app-testing.module'; -import { ContentApiService } from '@alfresco/aca-shared'; +import { AppExtensionService, ContentApiService } from '@alfresco/aca-shared'; import { of, Subject, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; import { NodeEntry, NodePaging } from '@alfresco/js-api'; @@ -39,6 +39,7 @@ describe('FilesComponent', () => { let fixture: ComponentFixture; let component: FilesComponent; let uploadService: UploadService; + let extensions: AppExtensionService; let nodeActionsService: NodeActionsService; let contentApi: ContentApiService; let route: ActivatedRoute; @@ -77,7 +78,8 @@ describe('FilesComponent', () => { params: of({ folderId: 'someId' }), queryParamMap: of({}) } - } + }, + AppExtensionService ], schemas: [NO_ERRORS_SCHEMA] }); @@ -96,6 +98,7 @@ describe('FilesComponent', () => { route = TestBed.inject(ActivatedRoute); nodeActionsService = TestBed.inject(NodeActionsService); contentApi = TestBed.inject(ContentApiService); + extensions = TestBed.inject(AppExtensionService); spyContent = spyOn(contentApi, 'getNode'); }); @@ -148,6 +151,24 @@ describe('FilesComponent', () => { expect(component.node).toBe(node); }); + it('should set columns', () => { + const filesDocumentListPresetMock = [ + { + id: 'app.files.modifiedOn', + key: 'modifiedAt', + type: 'date', + sortable: true, + desktopOnly: true, + template: 'template', + sortingKey: 'sorting-key' + } + ]; + + extensions.filesDocumentListPreset$ = of(filesDocumentListPresetMock); + fixture.detectChanges(); + expect(component.columns).toEqual(filesDocumentListPresetMock); + }); + it('should navigate to parent if node is not a folder', () => { const nodeEntry = { isFolder: false, parentId: 'parent-id' }; spyContent.and.returnValue(of({ entry: nodeEntry } as any)); diff --git a/projects/aca-content/src/lib/components/files/files.component.ts b/projects/aca-content/src/lib/components/files/files.component.ts index e4245ce93d..028005429d 100644 --- a/projects/aca-content/src/lib/components/files/files.component.ts +++ b/projects/aca-content/src/lib/components/files/files.component.ts @@ -127,7 +127,10 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { this.isAdmin = value; }); - this.columns = this.extensions.documentListPresets.files || []; + this.extensions.filesDocumentListPreset$.pipe(takeUntil(this.onDestroy$)).subscribe((preset) => { + this.columns = preset; + }); + if (this.queryParams && Object.keys(this.queryParams).length > 0) { this.isFilterHeaderActive = true; } diff --git a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts index a562b37936..0287ab2109 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts @@ -228,12 +228,15 @@ describe('AppExtensionService', () => { } }); - const { files, libraries } = service.documentListPresets; + const { libraries } = service.documentListPresets; + const files = service.filesDocumentListPreset$; - expect(files.length).toBe(3); - expect(files[0].id).toBe('app.files.thumbnail'); - expect(files[1].id).toBe('app.files.name'); - expect(files[2].id).toBe('app.files.securityMarks'); + files.subscribe((columns) => { + expect(columns.length).toBe(3); + expect(columns[0].id).toBe('app.files.thumbnail'); + expect(columns[1].id).toBe('app.files.name'); + expect(columns[2].id).toBe('app.files.securityMarks'); + }); expect(libraries.length).toBe(2); expect(libraries[0].id).toBe('app.libraries.name'); @@ -279,11 +282,13 @@ describe('AppExtensionService', () => { } }); - const { files } = service.documentListPresets; + const files = service.filesDocumentListPreset$; - expect(files.length).toBe(2); - expect(files[0].id).toBe('app.files.thumbnail'); - expect(files[1].id).toBe('app.files.name'); + files.subscribe((columns) => { + expect(columns.length).toBe(2); + expect(columns[0].id).toBe('app.files.thumbnail'); + expect(columns[1].id).toBe('app.files.name'); + }); }); }); diff --git a/projects/aca-shared/src/lib/services/app.extension.service.ts b/projects/aca-shared/src/lib/services/app.extension.service.ts index d28abdee0e..bb32e031ab 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.ts @@ -80,9 +80,9 @@ export class AppExtensionService implements RuleContext { private _createActions = new BehaviorSubject>([]); private _mainActions = new BehaviorSubject(null); private _sidebarActions = new BehaviorSubject>([]); + private _filesDocumentListPreset = new BehaviorSubject>([]); documentListPresets: { - files: Array; libraries: Array; favoriteLibraries: Array; shared: Array; @@ -91,7 +91,6 @@ export class AppExtensionService implements RuleContext { trashcan: Array; searchLibraries: Array; } = { - files: [], libraries: [], favoriteLibraries: [], shared: [], @@ -108,6 +107,7 @@ export class AppExtensionService implements RuleContext { withCredentials: boolean; references$: Observable; + filesDocumentListPreset$: Observable = this._filesDocumentListPreset.asObservable(); config: ExtensionConfig; @@ -158,6 +158,7 @@ export class AppExtensionService implements RuleContext { this._openWithActions.next(this.loader.getContentActions(config, 'features.viewer.openWith')); this._createActions.next(this.loader.getElements(config, 'features.create')); this._mainActions.next(this.loader.getFeatures(config).mainAction); + this._filesDocumentListPreset.next(this.getDocumentListPreset(config, 'files')); this.navbar = this.loadNavBar(config); this.sidebarTabs = this.loader.getElements(config, 'features.sidebar.tabs'); @@ -165,7 +166,6 @@ export class AppExtensionService implements RuleContext { this.search = this.loadSearchForms(config); this.documentListPresets = { - files: this.getDocumentListPreset(config, 'files'), libraries: this.getDocumentListPreset(config, 'libraries'), favoriteLibraries: this.getDocumentListPreset(config, 'favoriteLibraries'), shared: this.getDocumentListPreset(config, 'shared'), From 515b8832d2296a77d73d7b0314826160e16c8d0a Mon Sep 17 00:00:00 2001 From: Mykyta Maliarchuk Date: Mon, 28 Aug 2023 12:48:12 +0200 Subject: [PATCH 2/2] [ACS-5563] added DoneFn --- .../src/lib/services/app.extension.service.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts index 0287ab2109..e934155d32 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts @@ -174,7 +174,7 @@ describe('AppExtensionService', () => { }); }); - it('should support column orders', () => { + it('should support column orders', (done) => { applyConfig({ $id: 'test', $name: 'test', @@ -236,6 +236,7 @@ describe('AppExtensionService', () => { expect(columns[0].id).toBe('app.files.thumbnail'); expect(columns[1].id).toBe('app.files.name'); expect(columns[2].id).toBe('app.files.securityMarks'); + done(); }); expect(libraries.length).toBe(2); @@ -243,7 +244,7 @@ describe('AppExtensionService', () => { expect(libraries[1].id).toBe('app.libraries.thumbnail'); }); - it('should ignore column if visibility in rules is false', () => { + it('should ignore column if visibility in rules is false', (done) => { applyConfig({ $id: 'test', $name: 'test', @@ -288,6 +289,7 @@ describe('AppExtensionService', () => { expect(columns.length).toBe(2); expect(columns[0].id).toBe('app.files.thumbnail'); expect(columns[1].id).toBe('app.files.name'); + done(); }); }); });