From bce1aeb723242cd1007e1c66a4ac349d297eb3e2 Mon Sep 17 00:00:00 2001 From: siva kumar Date: Tue, 6 Oct 2020 19:25:42 +0530 Subject: [PATCH] [AAE-3637] Attach file - Upload button is not disabled when the user is in search mode (#6193) * [AAE-3637] Attach file - Upload button is not disabled when the user is in search mode * Add missing documentation for Input on the search filters * * Added warning message * * Added Unit tests to the recent changes * * Fixed css error * * Updated string Co-authored-by: adomi --- .../components/search-filter.component.md | 8 ++- ...tent-node-selector-panel.component.spec.ts | 57 ++++++++++++++++++- .../content-node-selector-panel.component.ts | 6 ++ .../content-node-selector.component.html | 8 +++ .../content-node-selector.component.scss | 9 +++ .../content-node-selector.component.spec.ts | 44 ++++++++++++++ .../content-node-selector.component.ts | 5 ++ lib/content-services/src/lib/i18n/en.json | 3 +- 8 files changed, 137 insertions(+), 3 deletions(-) diff --git a/docs/content-services/components/search-filter.component.md b/docs/content-services/components/search-filter.component.md index 80caaec232..e8b911d9c6 100644 --- a/docs/content-services/components/search-filter.component.md +++ b/docs/content-services/components/search-filter.component.md @@ -26,9 +26,15 @@ Represents a main container component for custom search and faceted search setti ## Basic usage ```html - + ``` +### Properties + +| Name | Type | Default value | Description | +| ---- | ---- | ------------- | ----------- | +| showContextFacets | `boolean` | true | Toggles whether to show or not the context facet filters | + ## Details The component UI uses dynamically created widgets to specify the search query and its 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 15eace5e2e..ac96f3b721 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 @@ -359,6 +359,7 @@ describe('ContentNodeSelectorPanelComponent', () => { describe('Search functionality', () => { let getCorrespondingNodeIdsSpy; + let customResourcesService: CustomResourcesService; const entry: Node = { id: 'fakeid'}; const defaultSearchOptions = (searchTerm, rootNodeId = undefined, skipCount = 0, showFiles = false) => { @@ -402,7 +403,7 @@ describe('ContentNodeSelectorPanelComponent', () => { spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); - const customResourcesService = TestBed.inject(CustomResourcesService); + customResourcesService = TestBed.inject(CustomResourcesService); getCorrespondingNodeIdsSpy = spyOn(customResourcesService, 'getCorrespondingNodeIds').and .callFake((id) => { if (id === '-sites-') { @@ -609,6 +610,60 @@ describe('ContentNodeSelectorPanelComponent', () => { expect(cnSearchSpy).toHaveBeenCalledWith('search', 'my-root-id', 0, 25, [], false); }); + it('should emit showingSearch event with true while searching', async () => { + spyOn(customResourcesService, 'hasCorrespondingNodeIds').and.returnValue(true); + const showingSearchSpy = spyOn(component.showingSearch, 'emit'); + component.search('search'); + + triggerSearchResults(fakeResultSetPaging); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.showingSearchResults).toBe(true); + expect(showingSearchSpy).toHaveBeenCalledWith(true); + }); + + it('should emit showingSearch event with false if you remove search term without clicking on X (icon) icon', async () => { + const showingSearchSpy = spyOn(component.showingSearch, 'emit'); + component.search(''); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.showingSearchResults).toBe(false); + expect(showingSearchSpy).toHaveBeenCalledWith(false); + }); + + it('should emit showingResults event with false when clicking on the X (clear) icon', () => { + const showingSearchSpy = spyOn(component.showingSearch, 'emit'); + component.chosenNode = [entry]; + + component.nodePaging = { + list: { + entries: [{ entry }] + } + }; + component.searchTerm = 'piccolo'; + component.showingSearchResults = true; + + component.clear(); + + expect(component.showingSearchResults).toBe(false); + expect(showingSearchSpy).toHaveBeenCalledWith(false); + }); + + it('should emit showingResults event with false if search api fails', async () => { + getCorrespondingNodeIdsSpy.and.throwError('Failed'); + const showingSearchSpy = spyOn(component.showingSearch, 'emit'); + component.search('search'); + + triggerSearchResults(fakeResultSetPaging); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.showingSearchResults).toBe(true); + expect(showingSearchSpy).toHaveBeenCalledWith(true); + }); + it('should the query restrict the search to the site and not to the currentFolderId in case is changed', () => { component.currentFolderId = 'my-root-id'; component.restrictRootToCurrentFolderId = true; 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 064138c216..853e5eb7e5 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 @@ -212,6 +212,10 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { @Output() siteChange: EventEmitter = new EventEmitter(); + /** Emitted on search input. */ + @Output() + showingSearch: EventEmitter = new EventEmitter(); + @ViewChild('documentList', { static: true }) documentList: DocumentListComponent; @@ -406,6 +410,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { this.pagination.maxItems = this.pageSize; this.resetChosenNode(); this.showingSearchResults = false; + this.showingSearch.emit(this.showingSearchResults); } /** @@ -464,6 +469,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { private showSearchResults(nodePaging: NodePaging): void { this.showingSearchResults = true; this.loadingSearchResults = false; + this.showingSearch.emit(this.showingSearchResults); this.nodePaging = nodePaging; } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html index 2cf8c7fbd3..be08f37312 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html @@ -21,6 +21,7 @@ [showDropdownSiteList]="data?.showDropdownSiteList" [showFilesInResult]="data?.showFilesInResult" (select)="onSelect($event)" + (showingSearch)="onShowingSearch($event)" (siteChange)="onSiteChange($event)" (navigationChange)="onNavigationChange($event)"> @@ -33,8 +34,15 @@ [staticTitle]="'FORM.FIELD.UPLOAD' | translate " [multipleFiles]="isMultipleSelection()" [rootFolderId]="currentDirectoryId" + [disabled]="disableUploadButton" (error)="onError($event)"> + +
+ warning + {{ 'NODE_SELECTOR.UPLOAD_BUTTON_WARNING_MESSAGE' | translate }} +
+