diff --git a/lib/content-services/search/components/search-chip-list/search-chip-list.component.html b/lib/content-services/search/components/search-chip-list/search-chip-list.component.html index 7a85b8ea9e..0a4c8276fc 100644 --- a/lib/content-services/search/components/search-chip-list/search-chip-list.component.html +++ b/lib/content-services/search/components/search-chip-list/search-chip-list.component.html @@ -10,10 +10,10 @@ - {{ (bucket.display || bucket.label) | translate }} + (remove)="searchFilter.unselectFacetBucket(selection.field, selection.bucket)"> + {{ (selection.bucket.display || selection.bucket.label) | translate }} cancel diff --git a/lib/content-services/search/components/search-chip-list/search-chip-list.component.spec.ts b/lib/content-services/search/components/search-chip-list/search-chip-list.component.spec.ts new file mode 100644 index 0000000000..55cc857cff --- /dev/null +++ b/lib/content-services/search/components/search-chip-list/search-chip-list.component.spec.ts @@ -0,0 +1,70 @@ +/*! + * @license + * Copyright 2016 - 2018 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Component } from '@angular/core'; +import { setupTestBed, CoreModule } from '@alfresco/adf-core'; +import { TestBed } from '@angular/core/testing'; +import { SearchModule } from '../../search.module'; + +@Component({ + selector: 'adf-test-component', + template: ` + + ` +}) +class TestComponent { + + searchFilter = { + selectedFacetQueries : [], + selectedBuckets: [], + unselectFacetQuery() {}, + unselectFacetBucket() {} + }; +} + +describe('SearchChipListComponent', () => { + + setupTestBed({ + imports: [ + CoreModule.forRoot(), + SearchModule + ], + declarations: [ + TestComponent + ] + }); + + it('should remove items from the search filter', () => { + const fixture = TestBed.createComponent(TestComponent); + const component: TestComponent = fixture.componentInstance; + + spyOn(component.searchFilter, 'unselectFacetQuery').and.stub(); + + component.searchFilter.selectedFacetQueries = [{ id: 1 }, { id: 2 }]; + + fixture.detectChanges(); + + const closeButtons = fixture.debugElement.nativeElement.querySelectorAll('.mat-chip-remove'); + expect(closeButtons.length).toBe(2); + + closeButtons[0].click(); + fixture.detectChanges(); + + expect(component.searchFilter.unselectFacetQuery).toHaveBeenCalledWith({ id: 1 }); + }); + +}); diff --git a/lib/content-services/search/components/search-filter/search-filter.component.ts b/lib/content-services/search/components/search-filter/search-filter.component.ts index fcf8178f23..9831747123 100644 --- a/lib/content-services/search/components/search-filter/search-filter.component.ts +++ b/lib/content-services/search/components/search-filter/search-filter.component.ts @@ -46,7 +46,7 @@ export class SearchFilterComponent implements OnInit, OnDestroy { canResetSelectedQueries = false; selectedFacetQueries: Array = []; - selectedBuckets: Array = []; + selectedBuckets: Array<{ field: FacetField, bucket: FacetFieldBucket }> = []; constructor(public queryBuilder: SearchQueryBuilderService, private searchService: SearchService, @@ -112,7 +112,13 @@ export class SearchFilterComponent implements OnInit, OnDestroy { this.selectedBuckets = []; for (let field of this.responseFacetFields) { if (field.buckets) { - this.selectedBuckets.push(...field.buckets.items.filter(bucket => bucket.checked)); + this.selectedBuckets.push( + ...field.buckets.items + .filter(bucket => bucket.checked) + .map(bucket => { + return { field, bucket }; + }) + ); } } } else {