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 2a4b7f952..686d49656 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 @@ -37,7 +37,6 @@ import { SetSelectedNodesAction, ShareNodeAction, UnlockWriteAction, - ViewNodeExtras, ViewNodeVersionAction } from '@alfresco/aca-shared/store'; import { NodeEffects } from '../store/effects/node.effects'; @@ -62,6 +61,7 @@ import { } from '@alfresco/adf-content-services'; import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component'; import { provideEffects } from '@ngrx/effects'; +import { ActivatedRoute, Router } from '@angular/router'; describe('ContentManagementService', () => { let dialog: MatDialog; @@ -77,6 +77,8 @@ describe('ContentManagementService', () => { let appHookService: AppHookService; let newVersionUploaderService: NewVersionUploaderService; let appSettingsService: AppSettingsService; + let router: Router; + let activatedRoute: ActivatedRoute; let showErrorSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef>; let showInfoSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef>; let showWarningSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef>; @@ -104,7 +106,8 @@ describe('ContentManagementService', () => { appHookService = TestBed.inject(AppHookService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService); appSettingsService = TestBed.inject(AppSettingsService); - + router = TestBed.inject(Router); + activatedRoute = TestBed.inject(ActivatedRoute); dialog = TestBed.inject(MatDialog); }); @@ -1618,12 +1621,47 @@ describe('ContentManagementService', () => { it('should dispatch ViewNodeVersionAction if dialog emit view action', () => { const fakeVersionId = '1'; - const fakeLocation: ViewNodeExtras = { - location: '/' - }; + const mockLocation = '/personal-files'; + activatedRoute.snapshot.queryParams = { location: mockLocation }; + spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion)); 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', () => { 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 bccc70564..1c2f3faaf 100644 --- a/projects/aca-content/src/lib/services/content-management.service.ts +++ b/projects/aca-content/src/lib/services/content-management.service.ts @@ -48,7 +48,7 @@ import { NodesApiService, ShareDialogComponent } 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 { inject, Injectable } from '@angular/core'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; @@ -56,7 +56,7 @@ import { Store } from '@ngrx/store'; import { forkJoin, Observable, of, zip } from 'rxjs'; import { catchError, map, mergeMap, take, tap } from 'rxjs/operators'; 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'; interface RestoredNode { @@ -76,25 +76,23 @@ interface SnackbarMessageData { providedIn: 'root' }) export class ContentManagementService { - private notificationService = inject(NotificationService); + private readonly notificationService = inject(NotificationService); + private readonly nodesApiService = inject(NodesApiService); + private readonly store = inject(Store); + 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"]'; - constructor( - private nodesApiService: NodesApiService, - private store: Store, - 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) { if (nodes && nodes.length > 0) { this.contentApi.addFavorite(nodes).subscribe(() => { @@ -618,13 +616,11 @@ export class ContentManagementService { this.documentListService.reload(); this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node)); break; - case NewVersionUploaderDataAction.view: - this.store.dispatch( - new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, { - location: this.router.url - }) - ); + case NewVersionUploaderDataAction.view: { + const location = this.activatedRoute.snapshot.queryParams['location'] || this.router.url; + this.store.dispatch(new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, { location })); break; + } default: break; }