[ADF-5176] - fixed apply when no value is given (#5841)

* [ADF-5176] - added check for when values are empty for headers

* [ADF-5176] - added test for the clear check
This commit is contained in:
Vito
2020-07-07 17:07:49 +01:00
committed by GitHub
parent ed12b13c87
commit 30e980837a
11 changed files with 86 additions and 16 deletions

View File

@@ -178,14 +178,14 @@ describe('SearchCheckListComponent', () => {
update: () => {}
};
component.settings = <any> { options: sizeOptions };
spyOn(component, 'flush').and.stub();
spyOn(component, 'submitValues').and.stub();
component.ngOnInit();
fixture.detectChanges();
const optionElements = fixture.debugElement.query(By.css('mat-checkbox'));
optionElements.triggerEventHandler('change', { checked: true });
expect(component.flush).toHaveBeenCalled();
expect(component.submitValues).toHaveBeenCalled();
const clearAllElement = fixture.debugElement.query(By.css('button[title="SEARCH.FILTER.ACTIONS.CLEAR-ALL"]'));
clearAllElement.triggerEventHandler('click', {} );

View File

@@ -74,13 +74,22 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
changeHandler(event: MatCheckboxChange, option: any) {
option.checked = event.checked;
this.flush();
this.submitValues();
}
flush() {
const checkedValues = this.options.items
hasValidValue() {
const checkedValues = this.getCheckedValues();
return !!checkedValues.length;
}
private getCheckedValues() {
return this.options.items
.filter((option) => option.checked)
.map((option) => option.value);
}
submitValues() {
const checkedValues = this.getCheckedValues();
this.isActive = !!checkedValues.length;

View File

@@ -129,10 +129,14 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
}
}
applyCurrentForm() {
submitValues() {
this.apply(this.form.value, this.form.valid);
}
hasValidValue() {
return this.form.valid;
}
reset() {
this.isActive = false;
this.form.reset({

View File

@@ -188,4 +188,25 @@ describe('SearchHeaderComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
});
it('should emit the clear event when no filter has valued applied', async (done) => {
spyOn(queryBuilder, 'isNoFilterActive').and.returnValue(true);
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
spyOn(component.widgetContainer, 'resetInnerWidget').and.stub();
component.widgetContainer.componentRef.instance.value = '';
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
component.clear.subscribe(() => {
done();
});
const menuButton: HTMLButtonElement = fixture.nativeElement.querySelector('#filter-menu-button');
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const applyButton = fixture.debugElement.query(By.css('#apply-filter-button'));
applyButton.triggerEventHandler('click', fakeEvent);
fixture.detectChanges();
await fixture.whenStable();
});
});

View File

@@ -129,15 +129,13 @@ export class SearchHeaderComponent implements OnInit, OnChanges, OnDestroy {
}
onApply() {
// TODO Move this piece of code in the search text widget
if (this.widgetContainer.selector === 'text' && this.widgetContainer.componentRef.instance.value === '') {
this.clearHeader();
return;
}
if (this.widgetContainer.hasValueSelected()) {
this.widgetContainer.applyInnerWidget();
this.searchHeaderQueryBuilder.setActiveFilter(this.category.columnKey);
this.searchHeaderQueryBuilder.execute();
} else {
this.clearHeader();
}
}
onClearButtonClick(event: Event) {

View File

@@ -100,6 +100,14 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
return result;
}
submitValues() {
this.apply(this.form.value, this.form.valid);
}
hasValidValue() {
return this.form.valid;
}
reset() {
this.isActive = false;

View File

@@ -83,6 +83,16 @@ export class SearchRadioComponent implements SearchWidget, OnInit {
return null;
}
submitValues() {
const currentValue = this.getSelectedValue();
this.setValue(currentValue);
}
hasValidValue() {
const currentValue = this.getSelectedValue();
return !!currentValue;
}
private setValue(newValue: string) {
this.value = newValue;
this.context.queryFragments[this.id] = newValue;

View File

@@ -70,6 +70,14 @@ export class SearchSliderComponent implements SearchWidget, OnInit {
this.updateQuery(this.value);
}
submitValues() {
this.updateQuery(this.value);
}
hasValidValue() {
return !!this.value;
}
private updateQuery(value: number | null) {
if (this.id && this.context && this.settings && this.settings.field) {
if (value === null) {

View File

@@ -71,6 +71,14 @@ export class SearchTextComponent implements SearchWidget, OnInit {
}
submitValues() {
this.updateQuery(this.value);
}
hasValidValue() {
return !!this.value;
}
private getSearchPrefix(): string {
return this.settings.searchPrefix ? this.settings.searchPrefix : '';
}

View File

@@ -77,9 +77,11 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy {
}
applyInnerWidget() {
if (this.selector === 'date-range' && this.componentRef && this.componentRef.instance) {
this.componentRef.instance.applyCurrentForm();
this.componentRef.instance.submitValues();
}
hasValueSelected() {
return this.componentRef.instance.hasValidValue();
}
resetInnerWidget() {

View File

@@ -24,4 +24,6 @@ export interface SearchWidget {
context?: SearchQueryBuilderService;
isActive?: boolean;
reset();
submitValues();
hasValidValue();
}