[ADF-5514] Fix red dot still present after filter being cleared (#8181)

* [ADF-5514] Fix red dot still present after filter being cleared

* Add unit test

* Added statement clearing filter after each test so the ordering doesn't cause the unit test to fail
This commit is contained in:
Thomas Hunter 2023-02-08 09:18:14 +00:00 committed by GitHub
parent 4c7e500ea8
commit 1a00249f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -74,6 +74,7 @@ describe('SearchFilterContainerComponent', () => {
});
afterEach(() => {
queryBuilder.removeActiveFilter(mockCategory.columnKey);
fixture.destroy();
});
@ -150,6 +151,32 @@ describe('SearchFilterContainerComponent', () => {
expect(eventRaised).toBe(true);
});
it('should hide the red dot after the filter is cleared', async () => {
const badge: HTMLElement = fixture.nativeElement.querySelector(`[data-automation-id="filter-menu-button"] .mat-badge-content`);
expect(window.getComputedStyle(badge).display).toBe('none');
const menuButton: HTMLButtonElement = fixture.nativeElement.querySelector('[data-automation-id="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('keypress', {key: 'Enter'});
fixture.detectChanges();
await fixture.whenStable();
expect(window.getComputedStyle(badge).display).not.toBe('none');
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
const clearButton = fixture.debugElement.query(By.css('#clear-filter-button'));
clearButton.triggerEventHandler('click', fakeEvent);
fixture.detectChanges();
await fixture.whenStable();
expect(window.getComputedStyle(badge).display).toBe('none');
});
describe('Accessibility', () => {
it('should set up a focus trap on the filter when the menu is opened', async () => {

View File

@ -35,6 +35,7 @@ import { SearchCategory } from '../../models/search-category.interface';
import { SEARCH_QUERY_SERVICE_TOKEN } from '../../search-query-service.token';
import { Subject } from 'rxjs';
import { MatMenuTrigger } from '@angular/material/menu';
import { FilterSearch } from '../../models/filter-search.interface';
@Component({
selector: 'adf-search-filter-container',
@ -119,7 +120,7 @@ export class SearchFilterContainerComponent implements OnInit, OnDestroy {
}
isActive(): boolean {
return this.widgetContainer && this.widgetContainer.componentRef && this.widgetContainer.componentRef.instance.isActive;
return this.searchFilterQueryBuilder.getActiveFilters().findIndex((f: FilterSearch) => f.key === this.category.columnKey) > -1;
}
onMenuOpen() {