From d64d076e80eca34810b4bc75d30993219d6c8664 Mon Sep 17 00:00:00 2001 From: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com> Date: Mon, 7 Sep 2026 14:34:51 +0200 Subject: [PATCH] [MNT-25876][ACS-12622] folders marked as favorites incorrectly redirects to personal files instead of repository (#5380) * [MNT-25876] Redirected when clicking favorited repository folders to repository * [MNT-25876] Unit tests * [MNT-25876] Unit tests --- .../favorites/favorites.component.spec.ts | 34 ++++++++++--------- .../favorites/favorites.component.ts | 20 +++-------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts b/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts index 06bcb58f3..d8acf1c7e 100644 --- a/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts +++ b/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts @@ -28,10 +28,13 @@ import { CustomResourcesService } from '@alfresco/adf-content-services'; import { BehaviorSubject, of, Subject } from 'rxjs'; import { FavoritesComponent } from './favorites.component'; import { AppTestingModule } from '../../testing/app-testing.module'; -import { AppService, ContentApiService } from '@alfresco/aca-shared'; +import { AppService, ContentApiService, initialState } from '@alfresco/aca-shared'; import { getTitleElementText } from '../../testing/test-utils'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { testHeader, testUploadEvents } from '../../testing/document-base-page-utils'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { NodeEntry } from '@alfresco/js-api'; +import { AppStore, NavigateToFolder } from '@alfresco/aca-shared/store'; describe('FavoritesComponent', () => { let fixture: ComponentFixture; @@ -39,6 +42,7 @@ describe('FavoritesComponent', () => { let contentApi: ContentApiService; let router: Router; let node; + let store: MockStore; beforeEach(() => { TestBed.configureTestingModule({ @@ -50,7 +54,8 @@ describe('FavoritesComponent', () => { appNavNarMode$: new BehaviorSubject('expanded'), toggleAppNavBar$: new Subject() } - } + }, + provideMockStore({ initialState }) ] }); @@ -79,37 +84,34 @@ describe('FavoritesComponent', () => { contentApi = TestBed.inject(ContentApiService); router = TestBed.inject(Router); spyOnProperty(router, 'url').and.returnValue('favorites'); + store = TestBed.inject(MockStore); }); describe('Node navigation', () => { + let loadedNode: NodeEntry; + beforeEach(() => { - spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node })); - spyOn(router, 'navigate').and.stub(); + loadedNode = { entry: node }; + spyOn(contentApi, 'getNode').and.returnValue(of(loadedNode)); fixture.detectChanges(); }); - it('navigates to `/libraries` if node path has `Sites`', () => { + it('should call dispatch on store during navigating if node is folder', () => { node.path.elements = [{ name: 'Sites' }]; + spyOn(store, 'dispatch'); component.navigate(node); - expect(router.navigate).toHaveBeenCalledWith(['/libraries', 'folder-node']); + expect(store.dispatch).toHaveBeenCalledWith(jasmine.objectContaining(new NavigateToFolder(loadedNode))); }); - it('navigates to `/personal-files` if node path has no `Sites`', () => { - node.path.elements = [{ name: 'something else' }]; - - component.navigate(node); - - expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'folder-node']); - }); - - it('does not navigate when node is not folder', () => { + it('should not call dispatch on store during navigating if node is not folder', () => { node.isFolder = false; + spyOn(store, 'dispatch'); component.navigate(node); - expect(router.navigate).not.toHaveBeenCalled(); + expect(store.dispatch).not.toHaveBeenCalled(); }); }); diff --git a/projects/aca-content/src/lib/components/favorites/favorites.component.ts b/projects/aca-content/src/lib/components/favorites/favorites.component.ts index 3e7891c5e..8b7591702 100644 --- a/projects/aca-content/src/lib/components/favorites/favorites.component.ts +++ b/projects/aca-content/src/lib/components/favorites/favorites.component.ts @@ -31,9 +31,9 @@ import { PaginationDirective, ToolbarComponent } from '@alfresco/aca-shared'; -import { Node, NodeEntry, PathElement, PathInfo } from '@alfresco/js-api'; +import { Node, NodeEntry } from '@alfresco/js-api'; import { Component, OnInit, ViewEncapsulation, inject } from '@angular/core'; -import { debounceTime, map } from 'rxjs/operators'; +import { debounceTime } from 'rxjs/operators'; import { DocumentListPresetRef, DynamicColumnComponent } from '@alfresco/adf-extensions'; import { CommonModule } from '@angular/common'; import { @@ -46,6 +46,7 @@ import { import { DocumentListDirective } from '../../directives/document-list.directive'; import { TranslatePipe } from '@ngx-translate/core'; import { DocumentListComponent } from '@alfresco/adf-content-services'; +import { NavigateToFolder } from '@alfresco/aca-shared/store'; @Component({ imports: [ @@ -86,19 +87,8 @@ export class FavoritesComponent extends PageComponent implements OnInit { } navigate(favorite: Node) { - const { isFolder, id } = favorite; - - // TODO: rework as it will fail on non-English setups - const isSitePath = (path: PathInfo): boolean => path?.elements?.some(({ name }: PathElement) => name === 'Sites'); - - if (isFolder) { - this.contentApi - .getNode(id) - .pipe(map((node) => node.entry)) - .subscribe(({ path }: Node) => { - const routeUrl = isSitePath(path) ? '/libraries' : '/personal-files'; - this.router.navigate([routeUrl, id]); - }); + if (favorite.isFolder) { + this.contentApi.getNode(favorite.id).subscribe((node) => this.store.dispatch(new NavigateToFolder(node))); } }