mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[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
This commit is contained in:
@@ -28,10 +28,13 @@ import { CustomResourcesService } from '@alfresco/adf-content-services';
|
|||||||
import { BehaviorSubject, of, Subject } from 'rxjs';
|
import { BehaviorSubject, of, Subject } from 'rxjs';
|
||||||
import { FavoritesComponent } from './favorites.component';
|
import { FavoritesComponent } from './favorites.component';
|
||||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
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 { getTitleElementText } from '../../testing/test-utils';
|
||||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||||
import { testHeader, testUploadEvents } from '../../testing/document-base-page-utils';
|
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', () => {
|
describe('FavoritesComponent', () => {
|
||||||
let fixture: ComponentFixture<FavoritesComponent>;
|
let fixture: ComponentFixture<FavoritesComponent>;
|
||||||
@@ -39,6 +42,7 @@ describe('FavoritesComponent', () => {
|
|||||||
let contentApi: ContentApiService;
|
let contentApi: ContentApiService;
|
||||||
let router: Router;
|
let router: Router;
|
||||||
let node;
|
let node;
|
||||||
|
let store: MockStore<AppStore>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -50,7 +54,8 @@ describe('FavoritesComponent', () => {
|
|||||||
appNavNarMode$: new BehaviorSubject('expanded'),
|
appNavNarMode$: new BehaviorSubject('expanded'),
|
||||||
toggleAppNavBar$: new Subject()
|
toggleAppNavBar$: new Subject()
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
provideMockStore({ initialState })
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -79,37 +84,34 @@ describe('FavoritesComponent', () => {
|
|||||||
contentApi = TestBed.inject(ContentApiService);
|
contentApi = TestBed.inject(ContentApiService);
|
||||||
router = TestBed.inject(Router);
|
router = TestBed.inject(Router);
|
||||||
spyOnProperty(router, 'url').and.returnValue('favorites');
|
spyOnProperty(router, 'url').and.returnValue('favorites');
|
||||||
|
store = TestBed.inject(MockStore);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Node navigation', () => {
|
describe('Node navigation', () => {
|
||||||
|
let loadedNode: NodeEntry;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
loadedNode = { entry: node };
|
||||||
spyOn(router, 'navigate').and.stub();
|
spyOn(contentApi, 'getNode').and.returnValue(of(loadedNode));
|
||||||
fixture.detectChanges();
|
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' }];
|
node.path.elements = [{ name: 'Sites' }];
|
||||||
|
spyOn(store, 'dispatch');
|
||||||
|
|
||||||
component.navigate(node);
|
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`', () => {
|
it('should not call dispatch on store during navigating if node is not folder', () => {
|
||||||
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', () => {
|
|
||||||
node.isFolder = false;
|
node.isFolder = false;
|
||||||
|
spyOn(store, 'dispatch');
|
||||||
|
|
||||||
component.navigate(node);
|
component.navigate(node);
|
||||||
|
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
expect(store.dispatch).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import {
|
|||||||
PaginationDirective,
|
PaginationDirective,
|
||||||
ToolbarComponent
|
ToolbarComponent
|
||||||
} from '@alfresco/aca-shared';
|
} 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 { 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 { DocumentListPresetRef, DynamicColumnComponent } from '@alfresco/adf-extensions';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import {
|
import {
|
||||||
@@ -46,6 +46,7 @@ import {
|
|||||||
import { DocumentListDirective } from '../../directives/document-list.directive';
|
import { DocumentListDirective } from '../../directives/document-list.directive';
|
||||||
import { TranslatePipe } from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||||
|
import { NavigateToFolder } from '@alfresco/aca-shared/store';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -86,19 +87,8 @@ export class FavoritesComponent extends PageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
navigate(favorite: Node) {
|
navigate(favorite: Node) {
|
||||||
const { isFolder, id } = favorite;
|
if (favorite.isFolder) {
|
||||||
|
this.contentApi.getNode(favorite.id).subscribe((node) => this.store.dispatch(new NavigateToFolder(node)));
|
||||||
// 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]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user