[MNT-25285] Unable to change version preview from within the preview window (#4789)

This commit is contained in:
dominikiwanekhyland
2025-09-10 13:05:53 +02:00
committed by GitHub
parent 732a11166c
commit 96b7c73915
2 changed files with 65 additions and 31 deletions

View File

@@ -37,7 +37,6 @@ import {
SetSelectedNodesAction, SetSelectedNodesAction,
ShareNodeAction, ShareNodeAction,
UnlockWriteAction, UnlockWriteAction,
ViewNodeExtras,
ViewNodeVersionAction ViewNodeVersionAction
} from '@alfresco/aca-shared/store'; } from '@alfresco/aca-shared/store';
import { NodeEffects } from '../store/effects/node.effects'; import { NodeEffects } from '../store/effects/node.effects';
@@ -62,6 +61,7 @@ import {
} from '@alfresco/adf-content-services'; } from '@alfresco/adf-content-services';
import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component'; import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component';
import { provideEffects } from '@ngrx/effects'; import { provideEffects } from '@ngrx/effects';
import { ActivatedRoute, Router } from '@angular/router';
describe('ContentManagementService', () => { describe('ContentManagementService', () => {
let dialog: MatDialog; let dialog: MatDialog;
@@ -77,6 +77,8 @@ describe('ContentManagementService', () => {
let appHookService: AppHookService; let appHookService: AppHookService;
let newVersionUploaderService: NewVersionUploaderService; let newVersionUploaderService: NewVersionUploaderService;
let appSettingsService: AppSettingsService; let appSettingsService: AppSettingsService;
let router: Router;
let activatedRoute: ActivatedRoute;
let showErrorSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>; let showErrorSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
let showInfoSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>; let showInfoSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
let showWarningSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>; let showWarningSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
@@ -104,7 +106,8 @@ describe('ContentManagementService', () => {
appHookService = TestBed.inject(AppHookService); appHookService = TestBed.inject(AppHookService);
newVersionUploaderService = TestBed.inject(NewVersionUploaderService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService);
appSettingsService = TestBed.inject(AppSettingsService); appSettingsService = TestBed.inject(AppSettingsService);
router = TestBed.inject(Router);
activatedRoute = TestBed.inject(ActivatedRoute);
dialog = TestBed.inject(MatDialog); dialog = TestBed.inject(MatDialog);
}); });
@@ -1618,12 +1621,47 @@ describe('ContentManagementService', () => {
it('should dispatch ViewNodeVersionAction if dialog emit view action', () => { it('should dispatch ViewNodeVersionAction if dialog emit view action', () => {
const fakeVersionId = '1'; const fakeVersionId = '1';
const fakeLocation: ViewNodeExtras = { const mockLocation = '/personal-files';
location: '/' activatedRoute.snapshot.queryParams = { location: mockLocation };
};
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion)); spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
contentManagementService.manageVersions(fakeNodeIsFile); contentManagementService.manageVersions(fakeNodeIsFile);
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, fakeLocation));
expect(spyOnDispatch).toHaveBeenCalledOnceWith(
new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, {
location: mockLocation
})
);
});
it('should dispatch ViewNodeVersionAction with location value from router.url if location param doesnt exist already', () => {
const fakeVersionId = '1';
const currentUrl = '/current-page';
activatedRoute.snapshot.queryParams = {};
spyOnProperty(router, 'url', 'get').and.returnValue(currentUrl);
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
contentManagementService.manageVersions(fakeNodeIsFile);
expect(spyOnDispatch).toHaveBeenCalledOnceWith(
new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, {
location: currentUrl
})
);
});
it('should dispatch ViewNodeVersionAction with the same location param if already exist', () => {
const fakeVersionId = '1';
const location = '/personal-files';
activatedRoute.snapshot.queryParams = { location: location };
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
contentManagementService.manageVersions(fakeNodeIsFile);
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, { location }));
}); });
it('should show permission error is node is not a file and does not have nodeId', () => { it('should show permission error is node is not a file and does not have nodeId', () => {

View File

@@ -48,7 +48,7 @@ import {
NodesApiService, NodesApiService,
ShareDialogComponent ShareDialogComponent
} from '@alfresco/adf-content-services'; } from '@alfresco/adf-content-services';
import { NotificationService, TranslationService, ConfirmDialogComponent, DialogComponent, DialogSize } from '@alfresco/adf-core'; import { ConfirmDialogComponent, DialogComponent, DialogSize, NotificationService, TranslationService } from '@alfresco/adf-core';
import { DeletedNodesPaging, Node, NodeEntry, PathInfo, SiteBodyCreate, SiteEntry } from '@alfresco/js-api'; import { DeletedNodesPaging, Node, NodeEntry, PathInfo, SiteBodyCreate, SiteEntry } from '@alfresco/js-api';
import { inject, Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
@@ -56,7 +56,7 @@ import { Store } from '@ngrx/store';
import { forkJoin, Observable, of, zip } from 'rxjs'; import { forkJoin, Observable, of, zip } from 'rxjs';
import { catchError, map, mergeMap, take, tap } from 'rxjs/operators'; import { catchError, map, mergeMap, take, tap } from 'rxjs/operators';
import { NodeActionsService } from './node-actions.service'; import { NodeActionsService } from './node-actions.service';
import { Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component'; import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component';
interface RestoredNode { interface RestoredNode {
@@ -76,25 +76,23 @@ interface SnackbarMessageData {
providedIn: 'root' providedIn: 'root'
}) })
export class ContentManagementService { export class ContentManagementService {
private notificationService = inject(NotificationService); private readonly notificationService = inject(NotificationService);
private readonly nodesApiService = inject(NodesApiService);
private readonly store = inject(Store<AppStore>);
private readonly contentApi = inject(ContentApiService);
private readonly permission = inject(NodePermissionService);
private readonly dialogRef = inject(MatDialog);
private readonly nodeActionsService = inject(NodeActionsService);
private readonly translation = inject(TranslationService);
private readonly nodeAspectService = inject(NodeAspectService);
private readonly activatedRoute = inject(ActivatedRoute);
private readonly appHookService = inject(AppHookService);
private readonly newVersionUploaderService = inject(NewVersionUploaderService);
private readonly router = inject(Router);
private readonly appSettingsService = inject(AppSettingsService);
private readonly documentListService = inject(DocumentListService);
private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]'; private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]';
constructor(
private nodesApiService: NodesApiService,
private store: Store<AppStore>,
private contentApi: ContentApiService,
private permission: NodePermissionService,
private dialogRef: MatDialog,
private nodeActionsService: NodeActionsService,
private translation: TranslationService,
private nodeAspectService: NodeAspectService,
private appHookService: AppHookService,
private newVersionUploaderService: NewVersionUploaderService,
private router: Router,
private appSettingsService: AppSettingsService,
private documentListService: DocumentListService
) {}
addFavorite(nodes: Array<NodeEntry>) { addFavorite(nodes: Array<NodeEntry>) {
if (nodes && nodes.length > 0) { if (nodes && nodes.length > 0) {
this.contentApi.addFavorite(nodes).subscribe(() => { this.contentApi.addFavorite(nodes).subscribe(() => {
@@ -618,13 +616,11 @@ export class ContentManagementService {
this.documentListService.reload(); this.documentListService.reload();
this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node)); this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node));
break; break;
case NewVersionUploaderDataAction.view: case NewVersionUploaderDataAction.view: {
this.store.dispatch( const location = this.activatedRoute.snapshot.queryParams['location'] || this.router.url;
new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, { this.store.dispatch(new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, { location }));
location: this.router.url
})
);
break; break;
}
default: default:
break; break;
} }