Skip to content

Commit

Permalink
[ACS-6486] in breadcrumb the file title is not updating after editing (
Browse files Browse the repository at this point in the history
…#4337)

* [ACS-6486] Update breadcrumb when file name is changed on details page

* [ACS-6486] Added unit tests

* [ACS-6486] Made injected services as readonly
  • Loading branch information
AleksanderSklorz authored Jan 15, 2025
1 parent 0c3542d commit 72e7405
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { DefaultProjectorFn, MemoizedSelector, Store } from '@ngrx/store';
import { ContentApiService } from '@alfresco/aca-shared';
import { AppStore, isInfoDrawerOpened, NavigateToFolder, NavigateToPreviousPage, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { NodeEntry, PathElement } from '@alfresco/js-api';
import { Node, NodeEntry, PathElement } from '@alfresco/js-api';
import { RouterTestingModule } from '@angular/router/testing';
import { AuthenticationService, CORE_PIPES, PageTitleService } from '@alfresco/adf-core';
import { BreadcrumbComponent, ContentService, SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { BreadcrumbComponent, ContentService, NodesApiService, SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { MatSnackBarModule } from '@angular/material/snack-bar';
Expand All @@ -44,6 +44,7 @@ describe('DetailsComponent', () => {
let fixture: ComponentFixture<DetailsComponent>;
let contentApiService: ContentApiService;
let contentService: ContentService;
let nodesApiService: NodesApiService;
let store: Store;
let node: NodeEntry;

Expand All @@ -62,6 +63,8 @@ describe('DetailsComponent', () => {
const mockAspectActionsSubject$ = new BehaviorSubject(mockAspectActions);
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(mockAspectActionsSubject$.asObservable());

const getBreadcrumb = (): BreadcrumbComponent => fixture.debugElement.query(By.directive(BreadcrumbComponent)).componentInstance;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, DetailsComponent, ...CORE_PIPES, MatSnackBarModule],
Expand Down Expand Up @@ -97,6 +100,7 @@ describe('DetailsComponent', () => {
component = fixture.componentInstance;
contentApiService = TestBed.inject(ContentApiService);
contentService = TestBed.inject(ContentService);
nodesApiService = TestBed.inject(NodesApiService);
store = TestBed.inject(Store);
storeMock.dispatch.calls.reset();

Expand Down Expand Up @@ -137,16 +141,29 @@ describe('DetailsComponent', () => {
});

it('should dispatch navigation to a given folder', () => {
const breadcrumbComponent: BreadcrumbComponent = fixture.debugElement.query(By.directive(BreadcrumbComponent)).componentInstance;
const pathElement: PathElement = {
id: 'fake-id'
};
breadcrumbComponent.navigate.emit(pathElement);
getBreadcrumb().navigate.emit(pathElement);
fixture.detectChanges();

expect(store.dispatch).toHaveBeenCalledWith(new NavigateToFolder({ entry: pathElement } as NodeEntry));
});

it('should pass different node as folderNode to breadcrumb when nodeUpdated from nodesApiService is triggered', () => {
fixture.detectChanges();
const breadcrumbComponent = getBreadcrumb();
const updatedNode = {
name: 'other node'
} as Node;

nodesApiService.nodeUpdated.next(updatedNode);
fixture.detectChanges();
expect(breadcrumbComponent.folderNode).toEqual(updatedNode);
expect(breadcrumbComponent.folderNode).not.toBe(updatedNode);
expect(updatedNode).not.toEqual(node.entry);
});

it('should dispatch node selection', () => {
fixture.detectChanges();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ActivatedRoute, NavigationStart } from '@angular/router';
import { ContentApiService, PageComponent, PageLayoutComponent, ToolbarComponent } from '@alfresco/aca-shared';
import { NavigateToFolder, NavigateToPreviousPage, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { merge, Subject } from 'rxjs';
import { BreadcrumbComponent, ContentService, PermissionListComponent } from '@alfresco/adf-content-services';
import { BreadcrumbComponent, ContentService, NodesApiService, PermissionListComponent } from '@alfresco/adf-content-services';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatIconModule } from '@angular/material/icon';
Expand All @@ -40,6 +40,7 @@ import { NodeEntry, PathElement } from '@alfresco/js-api';
import { first, takeUntil } from 'rxjs/operators';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { FileSizePipe, InfoDrawerButtonsDirective } from '@alfresco/adf-core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
standalone: true,
Expand Down Expand Up @@ -74,7 +75,12 @@ export class DetailsComponent extends PageComponent implements OnInit, OnDestroy

private readonly onDestroy$: Subject<void> = new Subject<void>();

constructor(private route: ActivatedRoute, private contentApi: ContentApiService, private contentService: ContentService) {
constructor(
private readonly route: ActivatedRoute,
private readonly contentApi: ContentApiService,
private readonly contentService: ContentService,
private readonly nodesApiService: NodesApiService
) {
super();
}

Expand All @@ -84,6 +90,7 @@ export class DetailsComponent extends PageComponent implements OnInit, OnDestroy
const { route } = this;
const { data } = route.snapshot;
this.title = data.title;
this.nodesApiService.nodeUpdated.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((node) => (this.node = { ...node }));
this.route.params.subscribe((params) => {
this.isLoading = true;
this.setActiveTab(params.activeTab);
Expand Down

0 comments on commit 72e7405

Please sign in to comment.