[ACA-3839] Document List - clear filter called multiple times (#5991)

* clear only when filter has value

* update tests

* fix lint
This commit is contained in:
Cilibiu Bogdan
2020-08-13 18:11:14 +03:00
committed by GitHub
parent 322587921c
commit 5f5867370c
2 changed files with 24 additions and 1 deletions

View File

@@ -168,6 +168,7 @@ describe('SearchHeaderComponent', () => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
spyOn(component.widgetContainer, 'resetInnerWidget').and.stub();
spyOn(component, 'isActive').and.returnValue(true);
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
component.clear.subscribe(() => {
done();
@@ -187,6 +188,7 @@ describe('SearchHeaderComponent', () => {
spyOn(queryBuilder, 'isNoFilterActive').and.returnValue(false);
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
spyOn(component, 'isActive').and.returnValue(true);
queryBuilder.queryFragments['fake'] = 'test';
spyOn(component.widgetContainer, 'resetInnerWidget').and.callThrough();
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
@@ -209,6 +211,7 @@ describe('SearchHeaderComponent', () => {
spyOn(queryBuilder, 'isNoFilterActive').and.returnValue(true);
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
spyOn(component, 'isActive').and.returnValue(true);
spyOn(component.widgetContainer, 'resetInnerWidget').and.stub();
component.widgetContainer.componentRef.instance.value = '';
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
@@ -226,6 +229,26 @@ describe('SearchHeaderComponent', () => {
await fixture.whenStable();
});
it('should not emit clear event when currentFolderNodeId changes and no filter was applied', async () => {
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
spyOn(component, 'isActive').and.returnValue(false);
spyOn(component.clear, 'emit');
component.ngOnChanges({ currentFolderNodeId: currentFolderNodeIdChange });
fixture.detectChanges();
expect(component.clear.emit).not.toHaveBeenCalled();
});
it('should emit clear event when currentFolderNodeId changes and filter was applied', async () => {
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
spyOn(component.clear, 'emit');
spyOn(component, 'isActive').and.returnValue(true);
component.ngOnChanges({ currentFolderNodeId: currentFolderNodeIdChange });
fixture.detectChanges();
expect(component.clear.emit).toHaveBeenCalled();
});
describe('Accessibility', () => {
it('should set up a focus trap on the filter when the menu is opened', async () => {

View File

@@ -172,7 +172,7 @@ export class SearchHeaderComponent implements OnInit, OnChanges, OnDestroy {
}
clearHeader() {
if (this.widgetContainer) {
if (this.widgetContainer && this.isActive()) {
this.widgetContainer.resetInnerWidget();
this.searchHeaderQueryBuilder.removeActiveFilter(this.category.columnKey);
this.selection.emit(this.searchHeaderQueryBuilder.getActiveFilters());