Skip to content

Commit

Permalink
[ACS-5347] New styles for facets and filters states (#8661)
Browse files Browse the repository at this point in the history
* [ACS-5347] New styles for facets and filters states

* [ACS-5347] Move ACA specific colors to ACA

* [ACS-5347] CR fixes
  • Loading branch information
MichalKinas committed Jun 14, 2023
1 parent 0a3cc56 commit afbf877
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
  {{ displayValue | translate }}
</span>
<ng-template #showAny><span class="adf-search-filter-ellipsis adf-filter-value">&nbsp;{{ 'SEARCH.FILTER.ANY' | translate }}</span></ng-template>
<mat-icon *ngIf="isPopulated(); else disabledIcon">keyboard_arrow_down</mat-icon>
<mat-icon *ngIf="isPopulated(); else disabledIcon">{{ chipIcon }}</mat-icon>
<ng-template #disabledIcon>
<mat-icon>remove</mat-icon>
</ng-template>
Expand All @@ -38,8 +38,8 @@
<adf-search-facet-field [field]="field" #facetField></adf-search-facet-field>
</ng-container>
<ng-container ngProjectAs="filter-actions">
<button mat-flat-button class="adf-search-action-button" color="accent" (click)="onRemove()" id="cancel-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.REMOVE' | translate }}
<button mat-button class="adf-search-action-button" (click)="onRemove()" id="cancel-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.CLEAR' | translate }}
</button>
<button mat-flat-button class="adf-search-action-button" color="primary" (click)="onApply()" id="apply-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.APPLY' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ describe('SearchFacetChipComponent', () => {
expect(icon).toEqual('keyboard_arrow_down');
});

it('should display arrow up icon when menu is opened', () => {
component.field.buckets.items = [{ count: 1, label: 'test', filterQuery: '' }];
component.onMenuOpen();
fixture.detectChanges();
const icon = fixture.debugElement.query(By.css('mat-chip mat-icon')).nativeElement.innerText;
expect(icon).toEqual('keyboard_arrow_up');
});

it('should display remove icon and disable facet when no items are loaded', () => {
const chip = fixture.debugElement.query(By.css('mat-chip'));
const icon = fixture.debugElement.query(By.css('mat-chip mat-icon')).nativeElement.innerText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ export class SearchFacetChipComponent {
facetFieldComponent: SearchFacetFieldComponent;

focusTrap: ConfigurableFocusTrap;
chipIcon = 'keyboard_arrow_down';

constructor(private focusTrapFactory: ConfigurableFocusTrapFactory) {}

onMenuOpen() {
if (this.menuContainer && !this.focusTrap) {
this.focusTrap = this.focusTrapFactory.create(this.menuContainer.nativeElement);
}
this.chipIcon = 'keyboard_arrow_up';
}

onClosed() {
this.focusTrap.destroy();
this.focusTrap = null;
this.chipIcon = 'keyboard_arrow_down';
}

onRemove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

&.adf-search-toggle-chip {
background: var(--adf-theme-background-card-color);
border: 2px solid var(--theme-accent-color);
border: 2px solid var(--theme-primary-color);

&.mat-chip::after {
background: unset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
&nbsp;{{ displayValue | translate }}
</span>
<ng-template #showAny><span class="adf-search-filter-ellipsis adf-filter-value">&nbsp;{{ 'SEARCH.FILTER.ANY' | translate }}</span></ng-template>
<mat-icon>keyboard_arrow_down</mat-icon>
<mat-icon>{{ chipIcon }}</mat-icon>
</mat-chip>

<mat-menu #menu="matMenu" backdropClass="adf-search-filter-chip-menu" (closed)="onClosed()">
Expand All @@ -39,8 +39,8 @@
</ng-container>

<ng-container ngProjectAs="filter-actions">
<button mat-flat-button class="adf-search-action-button" color="accent" (click)="onRemove()" id="cancel-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.REMOVE' | translate }}
<button mat-button class="adf-search-action-button" (click)="onRemove()" id="cancel-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.CLEAR' | translate }}
</button>
<button mat-flat-button class="adf-search-action-button" color="primary" (click)="onApply()" id="apply-filter-button">
{{ 'SEARCH.FILTER.BUTTONS.APPLY' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe('SearchWidgetChipComponent', () => {
let fixture: ComponentFixture<SearchWidgetChipComponent>;
let queryBuilder: SearchQueryBuilderService;

setupTestBed( {
imports: [
MatMenuModule,
TranslateModule.forRoot(),
ContentTestingModule
]
});
setupTestBed({
imports: [
MatMenuModule,
TranslateModule.forRoot(),
ContentTestingModule
]
});

beforeEach(() => {
queryBuilder = TestBed.inject(SearchQueryBuilderService);
Expand All @@ -46,23 +46,35 @@ describe('SearchWidgetChipComponent', () => {

component.category = simpleCategories[1];
fixture.detectChanges();
});
});

it('should update search query on apply click', () => {
it('should update search query on apply click', () => {
const chip = fixture.debugElement.query(By.css('mat-chip'));
chip.triggerEventHandler('click', { stopPropagation: () => null });
fixture.detectChanges();
const applyButton = fixture.debugElement.query(By.css('#apply-filter-button'));
applyButton.triggerEventHandler('click', {});
expect(queryBuilder.update).toHaveBeenCalled();
});
});

it('should update search query on cancel click', () => {
it('should update search query on cancel click', () => {
const chip = fixture.debugElement.query(By.css('mat-chip'));
chip.triggerEventHandler('click', { stopPropagation: () => null });
fixture.detectChanges();
const applyButton = fixture.debugElement.query(By.css('#cancel-filter-button'));
applyButton.triggerEventHandler('click', {});
expect(queryBuilder.update).toHaveBeenCalled();
});
});

it('should display arrow down icon', () => {
const icon = fixture.debugElement.query(By.css('mat-chip mat-icon')).nativeElement.innerText;
expect(icon).toEqual('keyboard_arrow_down');
});

it('should display arrow up icon when menu is opened', () => {
component.onMenuOpen();
fixture.detectChanges();
const icon = fixture.debugElement.query(By.css('mat-chip mat-icon')).nativeElement.innerText;
expect(icon).toEqual('keyboard_arrow_up');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ export class SearchWidgetChipComponent {
widgetContainerComponent: SearchWidgetContainerComponent;

focusTrap: ConfigurableFocusTrap;
chipIcon = 'keyboard_arrow_down';

constructor(private focusTrapFactory: ConfigurableFocusTrapFactory) {}

onMenuOpen() {
if (this.menuContainer && !this.focusTrap) {
this.focusTrap = this.focusTrapFactory.create(this.menuContainer.nativeElement);
}
this.chipIcon = 'keyboard_arrow_up';
}

onClosed() {
this.focusTrap.destroy();
this.focusTrap = null;
this.chipIcon = 'keyboard_arrow_down';
}

onRemove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,4 @@
[onReset]="resetObservable"
(phrasesChanged)="onPhraseChange($event, LogicalSearchFields.EXCLUDE)">
</adf-search-chip-input>

<div class="adf-facet-buttons" *ngIf="!settings?.hideDefaultAction">
<button mat-button color="primary" data-automation-id="logical-filter-btn-clear" (click)="reset()">
{{ 'SEARCH.FILTER.ACTIONS.CLEAR' | translate }}
</button>
<button mat-button color="primary" data-automation-id="logical-filter-btn-apply" (click)="submitValues()">
{{ 'SEARCH.FILTER.ACTIONS.APPLY' | translate }}
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ describe('SearchLogicalFilterComponent', () => {
fixture.detectChanges();
}

function clickApplyBtn() {
const applyBtn: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="logical-filter-btn-apply"]')).nativeElement;
applyBtn.click();
fixture.detectChanges();
}

it('should update display value on init', () => {
spyOn(component.displayValue$, 'next');
component.ngOnInit();
Expand Down Expand Up @@ -122,14 +116,13 @@ describe('SearchLogicalFilterComponent', () => {
expect(component.displayValue$.next).toHaveBeenCalled();
});

it('should reset value and display value when reset button is clicked', () => {
it('should reset value and display value when reset is called', () => {
const searchCondition: LogicalSearchCondition = { matchAll: ['test1'], matchAny: ['test2'], exclude: ['test3'] };
component.setValue(searchCondition);
fixture.detectChanges();
spyOn(component.context, 'update');
spyOn(component.displayValue$, 'next');
const resetBtn: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="logical-filter-btn-clear"]')).nativeElement;
resetBtn.click();
component.reset();
expect(component.context.queryFragments[component.id]).toBe('');
expect(component.context.update).toHaveBeenCalled();
expect(component.getCurrentValue()).toEqual({ matchAll: [], matchAny: [], exclude: [] });
Expand All @@ -140,7 +133,7 @@ describe('SearchLogicalFilterComponent', () => {
spyOn(component.context, 'update');
enterNewPhrase('test1', 0);
enterNewPhrase('test2', 0);
clickApplyBtn();
component.submitValues();
expect(component.context.update).toHaveBeenCalled();
expect(component.context.queryFragments[component.id]).toBe('((field1:"test1" AND field1:"test2") OR (field2:"test1" AND field2:"test2"))');
});
Expand All @@ -149,7 +142,7 @@ describe('SearchLogicalFilterComponent', () => {
spyOn(component.context, 'update');
enterNewPhrase('test3', 1);
enterNewPhrase('test4', 1);
clickApplyBtn();
component.submitValues();
expect(component.context.update).toHaveBeenCalled();
expect(component.context.queryFragments[component.id]).toBe('((field1:"test3" OR field1:"test4") OR (field2:"test3" OR field2:"test4"))');
});
Expand All @@ -158,7 +151,7 @@ describe('SearchLogicalFilterComponent', () => {
spyOn(component.context, 'update');
enterNewPhrase('test5', 2);
enterNewPhrase('test6', 2);
clickApplyBtn();
component.submitValues();
expect(component.context.update).toHaveBeenCalled();
expect(component.context.queryFragments[component.id]).toBe('((NOT field1:"test5" AND NOT field1:"test6") AND (NOT field2:"test5" AND NOT field2:"test6"))');
});
Expand All @@ -168,7 +161,7 @@ describe('SearchLogicalFilterComponent', () => {
enterNewPhrase('test1', 0);
enterNewPhrase('test2', 1);
enterNewPhrase('test3', 2);
clickApplyBtn();
component.submitValues();
const subQuery1 = '((field1:"test1") OR (field2:"test1"))';
const subQuery2 = '((field1:"test2") OR (field2:"test2"))';
const subQuery3 = '((NOT field1:"test3") AND (NOT field2:"test3"))';
Expand Down

0 comments on commit afbf877

Please sign in to comment.