diff --git a/projects/aca-content/src/lib/components/details/details.component.spec.ts b/projects/aca-content/src/lib/components/details/details.component.spec.ts index b3450c8e3..d66bedd2d 100644 --- a/projects/aca-content/src/lib/components/details/details.component.spec.ts +++ b/projects/aca-content/src/lib/components/details/details.component.spec.ts @@ -29,7 +29,7 @@ import { ActivatedRoute } from '@angular/router'; import { BehaviorSubject, of, Subject } from 'rxjs'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { Store } from '@ngrx/store'; -import { ContentApiService } from '@alfresco/aca-shared'; +import { AppHookService, ContentApiService } from '@alfresco/aca-shared'; import { NavigateToFolder, SetSelectedNodesAction } from '@alfresco/aca-shared/store'; import { Node, NodeEntry, PathElement } from '@alfresco/js-api'; import { RouterTestingModule } from '@angular/router/testing'; @@ -38,6 +38,7 @@ import { BreadcrumbComponent, ContentService, NodesApiService, SearchQueryBuilde import { By } from '@angular/platform-browser'; import { ContentActionRef } from '@alfresco/adf-extensions'; import { MatSnackBarModule } from '@angular/material/snack-bar'; +import { Location } from '@angular/common'; describe('DetailsComponent', () => { let component: DetailsComponent; @@ -45,6 +46,8 @@ describe('DetailsComponent', () => { let contentApiService: ContentApiService; let contentService: ContentService; let nodesApiService: NodesApiService; + let appHookService: AppHookService; + let location: Location; let store: Store; let node: NodeEntry; @@ -101,6 +104,8 @@ describe('DetailsComponent', () => { contentApiService = TestBed.inject(ContentApiService); contentService = TestBed.inject(ContentService); nodesApiService = TestBed.inject(NodesApiService); + appHookService = TestBed.inject(AppHookService); + location = TestBed.inject(Location); store = TestBed.inject(Store); storeMock.dispatch.calls.reset(); @@ -258,4 +263,12 @@ describe('DetailsComponent', () => { component.setActiveTab('permissions'); expect(component.activeTab).not.toBe(2); }); + + it('should navigate back when nodesDeleted event is triggered', () => { + const locationSpy = spyOn(location, 'back'); + fixture.detectChanges(); + appHookService.nodesDeleted.next(); + + expect(locationSpy).toHaveBeenCalled(); + }); }); diff --git a/projects/aca-content/src/lib/components/details/details.component.ts b/projects/aca-content/src/lib/components/details/details.component.ts index 40c566640..5b04ba913 100644 --- a/projects/aca-content/src/lib/components/details/details.component.ts +++ b/projects/aca-content/src/lib/components/details/details.component.ts @@ -24,10 +24,10 @@ import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { ContentApiService, PageComponent, PageLayoutComponent, ToolbarComponent } from '@alfresco/aca-shared'; +import { AppHookService, ContentApiService, PageComponent, PageLayoutComponent, ToolbarComponent } from '@alfresco/aca-shared'; import { NavigateToFolder, NavigateToPreviousPage, SetSelectedNodesAction } from '@alfresco/aca-shared/store'; import { BreadcrumbComponent, ContentService, NodesApiService, PermissionListComponent } from '@alfresco/adf-content-services'; -import { CommonModule } from '@angular/common'; +import { CommonModule, Location } from '@angular/common'; import { TranslateModule } from '@ngx-translate/core'; import { MatIconModule } from '@angular/material/icon'; import { MatTabsModule } from '@angular/material/tabs'; @@ -76,7 +76,9 @@ export class DetailsComponent extends PageComponent implements OnInit, OnDestroy private readonly route: ActivatedRoute, private readonly contentApi: ContentApiService, private readonly contentService: ContentService, - private readonly nodesApiService: NodesApiService + private readonly nodesApiService: NodesApiService, + private readonly appHookService: AppHookService, + private readonly location: Location ) { super(); } @@ -88,6 +90,7 @@ export class DetailsComponent extends PageComponent implements OnInit, OnDestroy const { data } = route.snapshot; this.title = data.title; this.nodesApiService.nodeUpdated.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((node) => (this.node = { ...node })); + this.appHookService.nodesDeleted.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.location.back()); this.route.params.subscribe((params) => { this.isLoading = true; this.setActiveTab(params.activeTab);