[ADF-5177] Search-header execute when enter is pressed (#5840)

* [ADF-5177] Filter execute on enter key down

* [ADF-5177] Add unit test
This commit is contained in:
Baptiste Mahé
2020-07-07 10:08:03 +02:00
committed by GitHub
parent a5a984164c
commit 4ae484c617
3 changed files with 22 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
<div (click)="onMenuClick($event)" class="adf-filter-container">
<div class="adf-filter-title">{{ 'SEARCH.SEARCH_HEADER.TITLE' | translate }}</div>
<adf-search-widget-container
(keydown.enter)="onApply()"
[id]="category?.id"
[selector]="category?.component?.selector"
[settings]="category?.component?.settings">
@@ -28,7 +29,7 @@
</button>
<button mat-button color="primary"
id="apply-filter-button"
class="adf-filter-apply-button" (click)="onApplyButtonClick()">
class="adf-filter-apply-button" (click)="onApply()">
{{ 'SEARCH.SEARCH_HEADER.APPLY' | translate | uppercase }}
</button>
</mat-dialog-actions>

View File

@@ -84,7 +84,7 @@ describe('SearchHeaderComponent', () => {
expect(element).not.toBeUndefined();
});
it('should emit the node paging received from the queryBuilder after the filter gets applied', async (done) => {
it('should emit the node paging received from the queryBuilder after the Apply button is clicked', async (done) => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
component.update.subscribe((newNodePaging) => {
@@ -102,6 +102,24 @@ describe('SearchHeaderComponent', () => {
await fixture.whenStable();
});
it('should emit the node paging received from the queryBuilder after the Enter key is pressed', async (done) => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
component.update.subscribe((newNodePaging) => {
expect(newNodePaging).toBe(fakeNodePaging);
done();
});
const menuButton: HTMLButtonElement = fixture.nativeElement.querySelector('#filter-menu-button');
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
component.widgetContainer.componentRef.instance.value = 'searchText';
const widgetContainer = fixture.debugElement.query(By.css('adf-search-widget-container'));
widgetContainer.triggerEventHandler('keydown.enter', {});
fixture.detectChanges();
await fixture.whenStable();
});
it('should execute a new query when the page size is changed', async (done) => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});

View File

@@ -128,7 +128,7 @@ export class SearchHeaderComponent implements OnInit, OnChanges, OnDestroy {
event.stopPropagation();
}
onApplyButtonClick() {
onApply() {
// TODO Move this piece of code in the search text widget
if (this.widgetContainer.selector === 'text' && this.widgetContainer.componentRef.instance.value === '') {
this.clearHeader();