diff --git a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.html b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.html index 4d66e2ba5..41309ba2e 100644 --- a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.html +++ b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.html @@ -1,5 +1,6 @@
+ -
+ - + \ No newline at end of file diff --git a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts index a1f48111a..3a09fb55d 100644 --- a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts @@ -54,7 +54,6 @@ describe('SearchInputControlComponent', () => { it('should not emit submit event if form is invalid', () => { component.searchTerm = ''; spyOn(component.submit, 'emit'); - component.searchSubmit(); expect(component.submit.emit).not.toHaveBeenCalled(); diff --git a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts index c4c601830..d5ddbb57a 100644 --- a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts @@ -90,6 +90,7 @@ export class SearchInputControlComponent implements OnInit { searchSubmit() { this.searchFieldFormControl.markAsTouched(); + const trimmedTerm = this.searchTerm?.trim(); if (this.searchFieldFormControl.valid && trimmedTerm?.length > 0) { this.submit.emit(trimmedTerm); diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.html b/projects/aca-content/src/lib/components/search/search-input/search-input.component.html index a5afe4838..5f647124f 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.html +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.html @@ -1,12 +1,10 @@ - @@ -22,12 +20,7 @@
arrow_drop_down -
@@ -43,13 +36,15 @@ (submit)="onSearchSubmit($event)" (searchChange)="onSearchChange($event)" /> - - {{ 'SEARCH.INPUT.HINT' | translate }} - - - {{ 'SEARCH.INPUT.REQUIRED' | translate }} - +
+ + {{ 'SEARCH.INPUT.HINT' | translate }} + + + {{ 'SEARCH.INPUT.REQUIRED' | translate }} + +
+
{ component.searchInputControl.searchFieldFormControl.setValue(''); component.searchInputControl.searchFieldFormControl.markAsTouched(); fixture.detectChanges(); + expect(getFirstError()).toBe('SEARCH.INPUT.REQUIRED'); }); @@ -79,6 +80,7 @@ describe('SearchInputComponent', () => { component.searchInputControl.searchFieldFormControl.setValue('test'); component.searchInputControl.searchFieldFormControl.markAsTouched(); fixture.detectChanges(); + const error = fixture.debugElement.query(By.directive(MatError)); expect(error).toBeNull(); }); @@ -88,6 +90,7 @@ describe('SearchInputComponent', () => { component.searchInputControl.searchFieldFormControl.setValue(''); component.searchInputControl.searchFieldFormControl.markAsUntouched(); fixture.detectChanges(); + const error = fixture.debugElement.query(By.directive(MatError)); expect(error).toBeNull(); }); @@ -96,8 +99,10 @@ describe('SearchInputComponent', () => { spyOn(component as any, 'isLibrariesChecked').and.returnValue(true); spyOn(component as any, 'isFoldersChecked').and.returnValue(false); spyOn(component as any, 'isFilesChecked').and.returnValue(false); + component.searchedWord = 'test'; component.onSearchSubmit('Enter'); + expect(store.dispatch).toHaveBeenCalled(); }); diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts index 39fd00a23..9390bd215 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts @@ -204,8 +204,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { this.syncInputValues(); this.has400LibraryError = false; - const searchTerm = this.searchedWord?.trim(); - if (!searchTerm) { + if (!this.searchedWord.trim()) { return; } @@ -213,8 +212,8 @@ export class SearchInputComponent implements OnInit, OnDestroy { this.hasLibrariesConstraint = this.evaluateLibrariesConstraint(); if (this.onLibrariesSearchResults && this.isSameSearchTerm()) { this.queryLibrariesBuilder.update(); - } else if (searchTerm) { - this.store.dispatch(new SearchByTermAction(searchTerm, this.searchOptions)); + } else if (this.searchedWord) { + this.store.dispatch(new SearchByTermAction(this.searchedWord, this.searchOptions)); } } else { if (this.isFoldersChecked() && !this.isFilesChecked()) { @@ -227,8 +226,8 @@ export class SearchInputComponent implements OnInit, OnDestroy { if (this.onSearchResults && this.isSameSearchTerm()) { this.queryBuilder.update(); - } else if (searchTerm) { - this.store.dispatch(new SearchByTermAction(searchTerm, this.searchOptions)); + } else if (this.searchedWord) { + this.store.dispatch(new SearchByTermAction(this.searchedWord, this.searchOptions)); } } }