From 2ce7eb7c7dd134632ab82ba2506fbfbdbeba1996 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Sat, 1 Feb 2020 07:58:51 +0200 Subject: [PATCH 1/2] set info drawer state based on location --- src/app/components/page.component.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts index ed0e259d2..3c76019d0 100644 --- a/src/app/components/page.component.ts +++ b/src/app/components/page.component.ts @@ -32,7 +32,7 @@ import { OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Store } from '@ngrx/store'; import { MinimalNodeEntity, MinimalNodeEntryEntity } from '@alfresco/js-api'; import { Observable, Subject, Subscription } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { takeUntil, map } from 'rxjs/operators'; import { AppExtensionService } from '../extensions/extension.service'; import { ContentManagementService } from '../services/content-management.service'; import { @@ -76,7 +76,12 @@ export abstract class PageComponent implements OnInit, OnDestroy { ngOnInit() { this.sharedPreviewUrl$ = this.store.select(getSharedUrl); - this.infoDrawerOpened$ = this.store.select(isInfoDrawerOpened); + this.infoDrawerOpened$ = this.store.select(isInfoDrawerOpened).pipe( + map(infoDrawerState => { + return !this.isOutletPreviewUrl() && infoDrawerState; + }) + ); + this.documentDisplayMode$ = this.store.select(getDocumentDisplayMode); this.store From 1389c0bf5fd737892e2d142b0ae9267d3b1d1c08 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Sat, 1 Feb 2020 07:59:53 +0200 Subject: [PATCH 2/2] update tests --- src/app/components/page.component.spec.ts | 86 ++++++++++++++++++++--- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/src/app/components/page.component.spec.ts b/src/app/components/page.component.spec.ts index 39cb70d2e..fd690f498 100644 --- a/src/app/components/page.component.spec.ts +++ b/src/app/components/page.component.spec.ts @@ -23,30 +23,55 @@ * along with Alfresco. If not, see . */ +import { TestBed, ComponentFixture } from '@angular/core/testing'; import { PageComponent } from './page.component'; import { ReloadDocumentListAction, - SetSelectedNodesAction + SetSelectedNodesAction, + SetInfoDrawerStateAction, + AppState, + AppStore } from '@alfresco/aca-shared/store'; import { MinimalNodeEntity } 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 { AppExtensionService } from '../extensions/extension.service'; +import { AppTestingModule } from '../testing/app-testing.module'; +import { Component } from '@angular/core'; -class TestClass extends PageComponent { +@Component({ + selector: 'aca-test', + template: '' +}) +class TestComponent extends PageComponent { node: any; - constructor(store) { - super(store, null, null); + constructor( + store: Store, + extensions: AppExtensionService, + content: ContentManagementService + ) { + super(store, extensions, content); } } describe('PageComponent', () => { - let component: TestClass; - const store = { - dispatch: jasmine.createSpy('dispatch'), - select: jasmine.createSpy('select') - }; + let component: TestComponent; + let store: Store; + let fixture: ComponentFixture; beforeEach(() => { - component = new TestClass(store); + TestBed.configureTestingModule({ + imports: [AppTestingModule, EffectsModule.forRoot([ViewerEffects])], + declarations: [TestComponent], + providers: [ContentManagementService, AppExtensionService] + }); + + store = TestBed.get(Store); + fixture = TestBed.createComponent(TestComponent); + component = fixture.componentInstance; }); describe('getParentNodeId()', () => { @@ -63,6 +88,42 @@ describe('PageComponent', () => { }); }); + describe('Info Drawer state', () => { + const locationHref = location.href; + + afterEach(() => { + window.history.pushState({}, null, locationHref); + }); + + it('should open info drawer on action event', done => { + window.history.pushState({}, null, `${locationHref}#test`); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + component.infoDrawerOpened$.subscribe(state => { + expect(state).toBe(true); + done(); + }); + }); + + store.dispatch(new SetInfoDrawerStateAction(true)); + }); + + it('should not open info drawer if viewer outlet is active', done => { + window.history.pushState({}, null, `${locationHref}#test(viewer:view)`); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + component.infoDrawerOpened$.subscribe(state => { + expect(state).toBe(false); + done(); + }); + }); + + store.dispatch(new SetInfoDrawerStateAction(true)); + }); + }); + describe('Reload', () => { const locationHref = location.href; @@ -72,11 +133,15 @@ describe('PageComponent', () => { it('should not reload if url contains viewer outlet', () => { window.history.pushState({}, null, `${locationHref}#test(viewer:view)`); + spyOn(store, 'dispatch'); + component.reload(); expect(store.dispatch).not.toHaveBeenCalled(); }); it('should reload if url does not contain viewer outlet', () => { + spyOn(store, 'dispatch'); + component.reload(); expect(store.dispatch).toHaveBeenCalledWith( new ReloadDocumentListAction() @@ -89,6 +154,7 @@ describe('PageComponent', () => { id: 'node-id' } } as MinimalNodeEntity; + spyOn(store, 'dispatch'); component.reload(node); expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(