From cf4af3bab5286ecb5c019aa829d03d0c68e5a724 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Tue, 11 Aug 2020 17:41:09 +0300 Subject: [PATCH] [ACA-3788] Viewer - toolbar disappears after refresh (#1592) * reset results if not in viewer outlet * update tests --- src/app/components/page.component.spec.ts | 48 ++++++++++++++++++++++- src/app/components/page.component.ts | 6 ++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/app/components/page.component.spec.ts b/src/app/components/page.component.spec.ts index 361ace8db..322a09742 100644 --- a/src/app/components/page.component.spec.ts +++ b/src/app/components/page.component.spec.ts @@ -27,13 +27,14 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { PageComponent } from './page.component'; import { ReloadDocumentListAction, SetSelectedNodesAction, SetInfoDrawerStateAction, AppState, AppStore } from '@alfresco/aca-shared/store'; import { AppExtensionService } from '@alfresco/aca-shared'; -import { MinimalNodeEntity } from '@alfresco/js-api'; +import { MinimalNodeEntity, NodePaging } from '@alfresco/js-api'; import { ContentManagementService } from '../services/content-management.service'; import { EffectsModule } from '@ngrx/effects'; import { ViewerEffects } from '../store/effects'; import { Store } from '@ngrx/store'; import { AppTestingModule } from '../testing/app-testing.module'; import { Component } from '@angular/core'; +import { DocumentListComponent } from '@alfresco/adf-content-services'; @Component({ selector: 'aca-test', @@ -147,5 +148,50 @@ describe('PageComponent', () => { component.reload(node); expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new SetSelectedNodesAction([node])); }); + + it('should update source on onFilterUpdate event', () => { + const nodePaging = { + list: { + pagination: {}, + entries: [{ entry: { id: 'new-node-id' } }] + } + } as NodePaging; + + component.onFilterUpdate(nodePaging); + expect(component.nodeResult).toEqual(nodePaging); + }); + + it('should clear results onAllFilterCleared event', () => { + component.documentList = { + node: { + list: { + pagination: {}, + entries: [{ entry: { id: 'new-node-id' } }] + } + } as NodePaging + } as DocumentListComponent; + spyOn(store, 'dispatch'); + + component.onAllFilterCleared(); + expect(component.documentList.node).toBe(null); + expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new ReloadDocumentListAction()); + }); + + it('should call onAllFilterCleared event if page is viewer outlet', () => { + window.history.pushState({}, null, `${locationHref}#test(viewer:view)`); + const nodePaging = { + list: { + pagination: {}, + entries: [{ entry: { id: 'new-node-id' } }] + } + } as NodePaging; + + component.documentList = { node: nodePaging } as DocumentListComponent; + spyOn(store, 'dispatch'); + + component.onAllFilterCleared(); + expect(component.documentList.node).toEqual(nodePaging); + expect(store.dispatch).not.toHaveBeenCalled(); + }); }); }); diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts index aba16b5ed..f32746f2d 100644 --- a/src/app/components/page.component.ts +++ b/src/app/components/page.component.ts @@ -165,7 +165,9 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges { } onAllFilterCleared() { - this.documentList.node = null; - this.store.dispatch(new ReloadDocumentListAction()); + if (!this.isOutletPreviewUrl()) { + this.documentList.node = null; + this.store.dispatch(new ReloadDocumentListAction()); + } } }