From 4a54e8523b6d84bfe73ddb22f651a0d4a0169b8b Mon Sep 17 00:00:00 2001 From: arditdomi <32884230+arditdomi@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:16:26 +0000 Subject: [PATCH] =?UTF-8?q?[AAE-4661]=20Fix=20search=20results=20are=20sti?= =?UTF-8?q?ll=20displayed=20when=20search=20term=20ge=E2=80=A6=20(#6707)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [AAE-4661] Fix search results are still displayed when search term gets deleted * Fix unit tests --- ...content-node-selector-panel.component.spec.ts | 16 ++++++++++++++++ .../content-node-selector-panel.component.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index 79b0c3fbf7..48fc2de566 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -243,6 +243,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it('should not show the breadcrumb if search was performed as last action', async () => { + component.searchTerm = 'mock-search-term'; triggerSearchResults(fakeResultSetPaging); fixture.detectChanges(); @@ -263,6 +264,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it('should show the breadcrumb for the selected node when search results are displayed', async () => { + component.searchTerm = 'mock-search-term'; triggerSearchResults(fakeResultSetPaging); const chosenNode = new Node({ path: { elements: ['one'] } }); @@ -642,6 +644,7 @@ describe('ContentNodeSelectorPanelComponent', () => { })); it('should emit showingSearch event with true while searching', async () => { + component.searchTerm = 'mock-search-term'; spyOn(customResourcesService, 'hasCorrespondingNodeIds').and.returnValue(true); const showingSearchSpy = spyOn(component.showingSearch, 'emit'); @@ -685,6 +688,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it('should emit showingResults event with false if search api fails', async () => { + component.searchTerm = 'mock-search-term'; getCorrespondingNodeIdsSpy.and.throwError('Failed'); const showingSearchSpy = spyOn(component.showingSearch, 'emit'); component.queryBuilderService.execute({ query: { query: 'search' } }); @@ -845,6 +849,18 @@ describe('ContentNodeSelectorPanelComponent', () => { }, 300); }); + it('should not show the result list when results are returned but there is no search term typed', (done) => { + component.searchTerm = ''; + + setTimeout(() => { + triggerSearchResults(fakeResultSetPaging); + fixture.detectChanges(); + + expect(component.showingSearchResults).toEqual(false); + done(); + }, 300); + }); + it('should highlight the results when search was performed in the next timeframe', (done) => { typeToSearchBox('My'); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts index 66edbed806..2f7426ce9a 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts @@ -304,7 +304,9 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { this.queryBuilderService.executed .pipe(takeUntil(this.onDestroy$)) .subscribe( (results: NodePaging) => { - this.showSearchResults(results); + if (this.searchTerm) { + this.showSearchResults(results); + } }); this.userPreferencesService