From a9780b352df02f2bd5bbf6787d51f36a496daa8f Mon Sep 17 00:00:00 2001
From: tamaragruszka <156320606+tamaragruszka@users.noreply.github.com>
Date: Mon, 11 Mar 2024 11:54:27 +0100
Subject: [PATCH] [ACS-6587] ACA: Viewer does not update after restoring
version and the toolbar disappears (#3669)
* [ACS-6587] update after restoring version
* [ACS-6587] update tests
* [ACS-6587] add tests and fixes
* resolve conflicts content-management.service.spec.ts
---
.../content-management.service.spec.ts | 9 +--
.../services/content-management.service.ts | 3 +-
.../viewer/viewer.component.spec.ts | 62 +++++++++++++++++++
.../lib/components/viewer/viewer.component.ts | 7 ++-
.../store/src/actions/viewer.actions.ts | 4 +-
5 files changed, 75 insertions(+), 10 deletions(-)
create mode 100644 projects/aca-content/viewer/src/lib/components/viewer/viewer.component.spec.ts
diff --git a/projects/aca-content/src/lib/services/content-management.service.spec.ts b/projects/aca-content/src/lib/services/content-management.service.spec.ts
index d32bba14a..d59cc0851 100644
--- a/projects/aca-content/src/lib/services/content-management.service.spec.ts
+++ b/projects/aca-content/src/lib/services/content-management.service.spec.ts
@@ -34,7 +34,7 @@ import {
NavigateToParentFolder,
NodeActionTypes,
PurgeDeletedNodesAction,
- ReloadDocumentListAction,
+ RefreshPreviewAction,
RestoreDeletedNodesAction,
SetSelectedNodesAction,
ShareNodeAction,
@@ -1608,10 +1608,11 @@ describe('ContentManagementService', () => {
expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[2]).toEqual(elementToFocusSelector);
});
- it('should dispatch ReloadDocumentListAction if dialog emit refresh action', () => {
- spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.refresh }));
+ it('should dispatch RefreshPreviewAction if dialog emit refresh action', () => {
+ spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.refresh, node: fakeNodeIsFile }));
contentManagementService.manageVersions(fakeNodeIsFile);
- expect(spyOnDispatch).toHaveBeenCalledOnceWith(new ReloadDocumentListAction());
+
+ expect(spyOnDispatch).toHaveBeenCalledOnceWith(new RefreshPreviewAction(fakeNodeIsFile));
});
it('should dispatch ReloadDocumentListAction if dialog emit view action', () => {
diff --git a/projects/aca-content/src/lib/services/content-management.service.ts b/projects/aca-content/src/lib/services/content-management.service.ts
index 9f16bd2b7..208e533b5 100644
--- a/projects/aca-content/src/lib/services/content-management.service.ts
+++ b/projects/aca-content/src/lib/services/content-management.service.ts
@@ -32,6 +32,7 @@ import {
NavigateRouteAction,
NavigateToParentFolder,
NodeInfo,
+ RefreshPreviewAction,
ReloadDocumentListAction,
SetSelectedNodesAction,
ShowLoaderAction,
@@ -581,7 +582,7 @@ export class ContentManagementService {
next: (newVersionUploaderData: NewVersionUploaderData) => {
switch (newVersionUploaderData.action) {
case NewVersionUploaderDataAction.refresh:
- this.store.dispatch(new ReloadDocumentListAction());
+ this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node));
break;
case NewVersionUploaderDataAction.view:
this.store.dispatch(
diff --git a/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.spec.ts b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.spec.ts
new file mode 100644
index 000000000..a48102bdf
--- /dev/null
+++ b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.spec.ts
@@ -0,0 +1,62 @@
+/*!
+ * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
+ *
+ * Alfresco Example Content Application
+ *
+ * This file is part of the Alfresco Example Content Application.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * The Alfresco Example Content Application is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The Alfresco Example Content Application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * from Hyland Software. If not, see .
+ */
+
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { AcaViewerComponent } from '@alfresco/aca-content/viewer';
+import { NodesApiService } from '@alfresco/adf-content-services';
+import { RefreshPreviewAction } from '@alfresco/aca-shared/store';
+import { Node } from '@alfresco/js-api';
+import { EMPTY } from 'rxjs';
+import { CoreTestingModule } from '@alfresco/adf-core';
+import { Store, StoreModule } from '@ngrx/store';
+
+describe('AcaViewerComponent', () => {
+ let fixture: ComponentFixture;
+ let component: AcaViewerComponent;
+ let nodesApiService: NodesApiService;
+ let store: Store;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [CoreTestingModule, StoreModule.forRoot({})]
+ });
+
+ store = TestBed.inject(Store);
+ spyOn(store, 'select').and.returnValue(EMPTY);
+ fixture = TestBed.createComponent(AcaViewerComponent);
+ component = fixture.componentInstance;
+ nodesApiService = TestBed.inject(NodesApiService);
+ });
+
+ describe('Load content', () => {
+ it('should call node update after RefreshPreviewAction is triggered', () => {
+ spyOn(nodesApiService.nodeUpdated, 'next');
+ component.ngOnInit();
+ const node = new Node();
+
+ store.dispatch(new RefreshPreviewAction(node));
+ expect(nodesApiService.nodeUpdated.next).toHaveBeenCalledWith(node);
+ });
+ });
+});
diff --git a/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts
index 24f2c18ff..8b5363a76 100644
--- a/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts
+++ b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts
@@ -174,7 +174,7 @@ export class AcaViewerComponent implements OnInit, OnDestroy {
});
}
if (nodeId) {
- this.displayNode(nodeId);
+ void this.displayNode(nodeId);
}
});
@@ -197,7 +197,8 @@ export class AcaViewerComponent implements OnInit, OnDestroy {
this.actions$
.pipe(ofType(ViewerActionTypes.RefreshPreview), takeUntil(this.onDestroy$))
.subscribe((action: RefreshPreviewAction) => {
- this.displayNode(action?.payload?.entry?.id);
+ this.nodesApiService.nodeUpdated.next(action.node);
+ void this.displayNode(action.node.id);
});
this.appHookService.nodesDeleted.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.navigateToFileLocation());
@@ -206,7 +207,7 @@ export class AcaViewerComponent implements OnInit, OnDestroy {
this.uploadService.fileUploadComplete.pipe(debounceTime(300), takeUntil(this.onDestroy$)).subscribe((file) => {
this.nodesApiService.nodeUpdated.next(file.data.entry);
- this.displayNode(file.data.entry.id);
+ void this.displayNode(file.data.entry.id);
});
this.previewLocation = this.router.url.substring(0, this.router.url.indexOf('/', 1)).replace(/\//g, '');
diff --git a/projects/aca-shared/store/src/actions/viewer.actions.ts b/projects/aca-shared/store/src/actions/viewer.actions.ts
index 60f7a70d5..b0f77d86f 100644
--- a/projects/aca-shared/store/src/actions/viewer.actions.ts
+++ b/projects/aca-shared/store/src/actions/viewer.actions.ts
@@ -23,7 +23,7 @@
*/
import { Action } from '@ngrx/store';
-import { NodeEntry } from '@alfresco/js-api';
+import { Node, NodeEntry } from '@alfresco/js-api';
export enum ViewerActionTypes {
ViewFile = 'VIEW_FILE',
@@ -71,7 +71,7 @@ export class ClosePreviewAction implements Action {
export class RefreshPreviewAction implements Action {
readonly type = ViewerActionTypes.RefreshPreview;
- constructor(public payload?: NodeEntry) {}
+ constructor(public node: Node) {}
}
export class PluginPreviewAction implements Action {