[AAE-4661] Fix search results are still displayed when search term ge… (#6707)

* [AAE-4661] Fix search results are still displayed when search term gets deleted

* Fix unit tests
This commit is contained in:
arditdomi
2021-02-22 20:16:26 +00:00
committed by GitHub
parent 88e0d016e3
commit 4a54e8523b
2 changed files with 19 additions and 1 deletions

View File

@@ -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');

View File

@@ -304,7 +304,9 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
this.queryBuilderService.executed
.pipe(takeUntil(this.onDestroy$))
.subscribe( (results: NodePaging) => {
if (this.searchTerm) {
this.showSearchResults(results);
}
});
this.userPreferencesService