[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
This commit is contained in:
tamaragruszka 2024-03-11 11:54:27 +01:00 committed by GitHub
parent b5d2193416
commit a9780b352d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 75 additions and 10 deletions

View File

@ -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', () => {

View File

@ -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(

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<AcaViewerComponent>;
let component: AcaViewerComponent;
let nodesApiService: NodesApiService;
let store: Store<any>;
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);
});
});
});

View File

@ -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<RefreshPreviewAction>(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, '');

View File

@ -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 {