diff --git a/src/app/components/trashcan/trashcan.component.spec.ts b/src/app/components/trashcan/trashcan.component.spec.ts index 5c257fc56..6257d8392 100644 --- a/src/app/components/trashcan/trashcan.component.spec.ts +++ b/src/app/components/trashcan/trashcan.component.spec.ts @@ -20,11 +20,13 @@ import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core'; import { TrashcanComponent } from './trashcan.component'; import { CommonModule } from '../../common/common.module'; import { LocationLinkComponent } from '../location-link/location-link.component'; +import { ContentManagementService } from '../../common/services/content-management.service'; describe('TrashcanComponent', () => { let fixture; let component; let alfrescoApi: AlfrescoApiService; + let contentService: ContentManagementService; let page; beforeEach(() => { @@ -45,6 +47,9 @@ describe('TrashcanComponent', () => { declarations: [ LocationLinkComponent, TrashcanComponent + ], + providers: [ + ContentManagementService ] }) .compileComponents() @@ -53,6 +58,7 @@ describe('TrashcanComponent', () => { component = fixture.componentInstance; alfrescoApi = TestBed.get(AlfrescoApiService); + contentService = TestBed.get(ContentManagementService); component.documentList = { loadTrashcan: jasmine.createSpy('loadTrashcan'), @@ -65,6 +71,17 @@ describe('TrashcanComponent', () => { spyOn(alfrescoApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(page)); }); + describe('onRestoreNode()', () => { + it('should call refresh()', () => { + spyOn(component, 'refresh'); + fixture.detectChanges(); + + contentService.restoreNode.next(); + + expect(component.refresh).toHaveBeenCalled(); + }); + }); + describe('refresh()', () => { it('calls child component to reload', () => { component.refresh(); diff --git a/src/app/components/trashcan/trashcan.component.ts b/src/app/components/trashcan/trashcan.component.ts index a263f5dfc..9dc0040b1 100644 --- a/src/app/components/trashcan/trashcan.component.ts +++ b/src/app/components/trashcan/trashcan.component.ts @@ -15,17 +15,32 @@ * limitations under the License. */ -import { Component, ViewChild } from '@angular/core'; +import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; +import { Subscription } from 'rxjs/Rx'; + import { DocumentListComponent } from '@alfresco/adf-content-services'; +import { ContentManagementService } from '../../common/services/content-management.service'; @Component({ templateUrl: './trashcan.component.html' }) -export class TrashcanComponent { +export class TrashcanComponent implements OnInit, OnDestroy { + private subscriptions: Subscription[] = []; + @ViewChild(DocumentListComponent) documentList; + constructor(private contentManagementService: ContentManagementService) {} + + ngOnInit() { + this.subscriptions.push(this.contentManagementService.restoreNode.subscribe(() => this.refresh())); + } + refresh(): void { this.documentList.loadTrashcan(); this.documentList.resetSelection(); } + + ngOnDestroy() { + this.subscriptions.forEach(s => s.unsubscribe()); + } }