mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-3406] fix chip list integration regression (#3634)
* fix chip list integration * add unit test
This commit is contained in:
committed by
Eugenio Romano
parent
357e09689b
commit
f9195e4e27
@@ -10,10 +10,10 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="searchFilter && searchFilter.selectedBuckets.length">
|
<ng-container *ngIf="searchFilter && searchFilter.selectedBuckets.length">
|
||||||
<mat-chip
|
<mat-chip
|
||||||
*ngFor="let bucket of searchFilter.selectedBuckets"
|
*ngFor="let selection of searchFilter.selectedBuckets"
|
||||||
[removable]="true"
|
[removable]="true"
|
||||||
(remove)="searchFilter.unselectFacetBucket(bucket)">
|
(remove)="searchFilter.unselectFacetBucket(selection.field, selection.bucket)">
|
||||||
{{ (bucket.display || bucket.label) | translate }}
|
{{ (selection.bucket.display || selection.bucket.label) | translate }}
|
||||||
<mat-icon matChipRemove>cancel</mat-icon>
|
<mat-icon matChipRemove>cancel</mat-icon>
|
||||||
</mat-chip>
|
</mat-chip>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@@ -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: `
|
||||||
|
<adf-search-chip-list [searchFilter]="searchFilter"></adf-search-chip-list>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
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 });
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -46,7 +46,7 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
|||||||
canResetSelectedQueries = false;
|
canResetSelectedQueries = false;
|
||||||
|
|
||||||
selectedFacetQueries: Array<FacetQuery> = [];
|
selectedFacetQueries: Array<FacetQuery> = [];
|
||||||
selectedBuckets: Array<FacetFieldBucket> = [];
|
selectedBuckets: Array<{ field: FacetField, bucket: FacetFieldBucket }> = [];
|
||||||
|
|
||||||
constructor(public queryBuilder: SearchQueryBuilderService,
|
constructor(public queryBuilder: SearchQueryBuilderService,
|
||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
@@ -112,7 +112,13 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.selectedBuckets = [];
|
this.selectedBuckets = [];
|
||||||
for (let field of this.responseFacetFields) {
|
for (let field of this.responseFacetFields) {
|
||||||
if (field.buckets) {
|
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 {
|
} else {
|
||||||
|
Reference in New Issue
Block a user