diff --git a/src/app/components/layout/app-layout/app-layout.component.spec.ts b/src/app/components/layout/app-layout/app-layout.component.spec.ts index 701ac1d6c..56c5c6b80 100644 --- a/src/app/components/layout/app-layout/app-layout.component.spec.ts +++ b/src/app/components/layout/app-layout/app-layout.component.spec.ts @@ -41,7 +41,7 @@ class MockRouter { events = this.subject.asObservable(); routerState = { snapshot: { url: this.url } }; - navigate(url: string) { + navigateByUrl(url: string) { const navigationStart = new NavigationStart(0, url); this.subject.next(navigationStart); } @@ -143,11 +143,24 @@ describe('AppLayoutComponent', () => { const selection = [{ entry: { id: 'nodeId', name: 'name' } }]; store.dispatch(new SetSelectedNodesAction(selection)); - router.navigate(['somewhere/over/the/rainbow']); + router.navigateByUrl('somewhere/over/the/rainbow'); fixture.detectChanges(); store.select(appSelection).subscribe(state => { expect(state.isEmpty).toBe(true); done(); }); }); + + it('should not reset selection if route is `/search`', done => { + fixture.detectChanges(); + const selection = [{ entry: { id: 'nodeId', name: 'name' } }]; + store.dispatch(new SetSelectedNodesAction(selection)); + + router.navigateByUrl('/search;q='); + fixture.detectChanges(); + store.select(appSelection).subscribe(state => { + expect(state.isEmpty).toBe(false); + done(); + }); + }); }); diff --git a/src/app/components/layout/app-layout/app-layout.component.ts b/src/app/components/layout/app-layout/app-layout.component.ts index 1bf756966..7ad898d83 100644 --- a/src/app/components/layout/app-layout/app-layout.component.ts +++ b/src/app/components/layout/app-layout/app-layout.component.ts @@ -135,7 +135,13 @@ export class AppLayoutComponent implements OnInit, OnDestroy { this.router.events .pipe( - filter(event => event instanceof NavigationStart), + filter(event => { + return ( + event instanceof NavigationStart && + // search employs reuse route strategy + !event.url.startsWith('/search;') + ); + }), takeUntil(this.onDestroy$) ) .subscribe(() => this.store.dispatch(new SetSelectedNodesAction([])));