@@ -16,13 +16,14 @@ import {
1616 IgxGridExternalAdvancedFilteringComponent ,
1717 IgxGridAdvancedFilteringBindingComponent ,
1818 IgxGridAdvancedFilteringOverlaySettingsComponent ,
19- IgxGridAdvancedFilteringDynamicColumnsComponent
19+ IgxGridAdvancedFilteringDynamicColumnsComponent ,
20+ IgxGridAdvancedFilteringWithToolbarComponent
2021} from '../../test-utils/grid-samples.spec' ;
2122import { ControlsFunction } from '../../test-utils/controls-functions.spec' ;
2223import { FormattedValuesFilteringStrategy } from '../../data-operations/filtering-strategy' ;
2324import { IgxHierGridExternalAdvancedFilteringComponent } from '../../test-utils/hierarchical-grid-components.spec' ;
2425import { IgxHierarchicalGridComponent } from '../hierarchical-grid/public_api' ;
25- import { IFilteringEventArgs } from '../public_api' ;
26+ import { IFilteringEventArgs , IgxGridToolbarAdvancedFilteringComponent } from '../public_api' ;
2627import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
2728import { By } from '@angular/platform-browser' ;
2829import { IgxDateTimeEditorDirective } from '../../directives/date-time-editor/date-time-editor.directive' ;
@@ -43,7 +44,8 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
4344 IgxGridExternalAdvancedFilteringComponent ,
4445 IgxGridAdvancedFilteringBindingComponent ,
4546 IgxHierGridExternalAdvancedFilteringComponent ,
46- IgxGridAdvancedFilteringDynamicColumnsComponent
47+ IgxGridAdvancedFilteringDynamicColumnsComponent ,
48+ IgxGridAdvancedFilteringWithToolbarComponent
4749 ]
4850 } ) ;
4951 } ) ) ;
@@ -3157,6 +3159,65 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
31573159
31583160 } ) ;
31593161
3162+ describe ( 'Advanced filtering with toolbar' , ( ) => {
3163+ let fix : ComponentFixture < IgxGridAdvancedFilteringWithToolbarComponent > ;
3164+ let grid : IgxGridComponent ;
3165+
3166+ beforeEach ( fakeAsync ( ( ) => {
3167+ fix = TestBed . createComponent ( IgxGridAdvancedFilteringWithToolbarComponent ) ;
3168+ grid = fix . componentInstance . grid ;
3169+ fix . detectChanges ( ) ;
3170+ } ) ) ;
3171+
3172+ it ( 'Should update toolbar when advancedFilteringExpressionsTreeChange emits a new value' , fakeAsync ( ( ) => {
3173+ // Set initial filtering expressions tree
3174+ const tree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
3175+ tree . filteringOperands . push ( {
3176+ fieldName : 'ProductName' ,
3177+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
3178+ searchVal : 'angular' ,
3179+ ignoreCase : true
3180+ } ) ;
3181+
3182+ // Apply the initial filtering tree
3183+ grid . advancedFilteringExpressionsTree = tree ;
3184+ fix . detectChanges ( ) ;
3185+
3186+ // Create a new filtering tree with more filters
3187+ const updatedTree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
3188+ updatedTree . filteringOperands . push ( {
3189+ fieldName : 'Downloads' ,
3190+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'equals' ) ,
3191+ searchVal : 10 ,
3192+ ignoreCase : true
3193+ } ) ;
3194+ updatedTree . filteringOperands . push ( {
3195+ fieldName : 'ProductName' ,
3196+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
3197+ searchVal : 'angular' ,
3198+ ignoreCase : true
3199+ } ) ;
3200+ updatedTree . filteringOperands . push ( {
3201+ fieldName : 'Category' ,
3202+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'equals' ) ,
3203+ searchVal : 'electronics' ,
3204+ ignoreCase : false
3205+ } ) ;
3206+
3207+ // Update the filtering expressions tree
3208+ grid . advancedFilteringExpressionsTree = updatedTree ;
3209+ fix . detectChanges ( ) ;
3210+
3211+ // Verify the correct number of filters
3212+ const toolbarDebugElement = fix . debugElement . query ( By . directive ( IgxGridToolbarAdvancedFilteringComponent ) ) ;
3213+ const toolbarComponent = toolbarDebugElement . componentInstance as IgxGridToolbarAdvancedFilteringComponent ;
3214+ const numberOfFilters = ( toolbarComponent as any ) . numberOfColumns ;
3215+
3216+ expect ( grid . advancedFilteringExpressionsTree . filteringOperands . length ) . toEqual ( 3 ) ;
3217+ expect ( numberOfFilters ) . toEqual ( 3 ) ;
3218+ } ) ) ;
3219+ } )
3220+
31603221 describe ( 'Localization - ' , ( ) => {
31613222 it ( 'Should correctly change resource strings for Advanced Filtering dialog.' , fakeAsync ( ( ) => {
31623223 const fix = TestBed . createComponent ( IgxGridAdvancedFilteringComponent ) ;
0 commit comments