diff --git a/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.spec.ts b/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.spec.ts index 284576baf..210c476eb 100644 --- a/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.spec.ts +++ b/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.spec.ts @@ -75,6 +75,25 @@ describe('SamHierarchicalAutocompleteComponent', () => { expect(emptyItem).toBeTruthy(); })); + it('Should have results with minimumCharacterCountSearch', fakeAsync(() => { + + const event = { + "key": "Space", + "target": { "value": 'Level 7' } + } + component.configuration.minimumCharacterCountSearch = 3; + component.onKeyup(event); + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + const list = fixture.debugElement.query(By.css('.autocomplete-result')); + expect(list.nativeElement.children.length).toBe(3); + + })); + + + + it('Should have results key press', fakeAsync(() => { const event = { @@ -90,6 +109,24 @@ describe('SamHierarchicalAutocompleteComponent', () => { expect(component.results[0]['highlighted']).toBeTruthy(); })); + + + it('Should have empty results key press minimumCharacterCountSearch', fakeAsync(() => { + const event = { + "key": "d", + "target": { "value": 'id' } + } + component.configuration.minimumCharacterCountSearch = 3; + component.onKeyup(event); + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + const list = fixture.debugElement.query(By.css('.autocomplete-result')); + expect(list).toBe(null); + })); + + + it('Should have reuslts on focus', fakeAsync(() => { component.inputFocusHandler(); fixture.detectChanges(); diff --git a/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.ts b/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.ts index 67dcb2322..60c85b9ac 100644 --- a/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.ts +++ b/src/ui-kit/experimental/hierarchical/autocomplete/autocomplete.component.ts @@ -232,22 +232,24 @@ export class SamHierarchicalAutocompleteComponent { * @param searchString */ private getResults(searchString: string): void { - if (!this.matchPastSearchString(searchString) || - (this.matchPastSearchString(searchString) && !this.showResults) - || this.matchPastSearchString('')) { - this.searchString = searchString; - window.clearTimeout(this.timeoutNumber); - this.timeoutNumber = window.setTimeout(() => { - this.service.getDataByText(0, searchString).subscribe( - (result) => { - this.results = result.items; - this.maxResults = result.totalItems; - this.highlightedIndex = 0; - this.setHighlightedItem(this.results[this.highlightedIndex]); - this.showResults = true; - this.addScreenReaderMessage(this.maxResults + ' ' + this.resultsAvailableMessage) - }); - }, this.configuration.debounceTime); + if (searchString.length >= this.configuration.minimumCharacterCountSearch) { + if (!this.matchPastSearchString(searchString) || + (this.matchPastSearchString(searchString) && !this.showResults) + || this.matchPastSearchString('')) { + this.searchString = searchString; + window.clearTimeout(this.timeoutNumber); + this.timeoutNumber = window.setTimeout(() => { + this.service.getDataByText(0, searchString).subscribe( + (result) => { + this.results = result.items; + this.maxResults = result.totalItems; + this.highlightedIndex = 0; + this.setHighlightedItem(this.results[this.highlightedIndex]); + this.showResults = true; + this.addScreenReaderMessage(this.maxResults + ' ' + this.resultsAvailableMessage) + }); + }, this.configuration.debounceTime); + } } } diff --git a/src/ui-kit/experimental/hierarchical/hierarchical/hierarchical.component.html b/src/ui-kit/experimental/hierarchical/hierarchical/hierarchical.component.html index 073344bac..e8ab86e94 100644 --- a/src/ui-kit/experimental/hierarchical/hierarchical/hierarchical.component.html +++ b/src/ui-kit/experimental/hierarchical/hierarchical/hierarchical.component.html @@ -1,9 +1,5 @@ -