@@ -16,12 +16,13 @@ import {
1616 IgxGridExternalAdvancedFilteringComponent ,
1717 IgxGridAdvancedFilteringBindingComponent ,
1818 IgxGridAdvancedFilteringDynamicColumnsComponent ,
19- IgxGridAdvancedFilteringSerializedTreeComponent
19+ IgxGridAdvancedFilteringSerializedTreeComponent ,
20+ IgxGridAdvancedFilteringWithToolbarComponent
2021} from '../../test-utils/grid-samples.spec' ;
2122import { FormattedValuesFilteringStrategy } from '../../data-operations/filtering-strategy' ;
2223import { IgxHierGridExternalAdvancedFilteringComponent } from '../../test-utils/hierarchical-grid-components.spec' ;
2324import { IgxHierarchicalGridComponent } from '../hierarchical-grid/public_api' ;
24- import { IFilteringEventArgs } from '../public_api' ;
25+ import { IFilteringEventArgs , IgxGridToolbarAdvancedFilteringComponent } from '../public_api' ;
2526import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
2627import { QueryBuilderFunctions } from '../../query-builder/query-builder-functions.spec' ;
2728import { By } from '@angular/platform-browser' ;
@@ -38,7 +39,8 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
3839 IgxGridExternalAdvancedFilteringComponent ,
3940 IgxGridAdvancedFilteringBindingComponent ,
4041 IgxHierGridExternalAdvancedFilteringComponent ,
41- IgxGridAdvancedFilteringDynamicColumnsComponent
42+ IgxGridAdvancedFilteringDynamicColumnsComponent ,
43+ IgxGridAdvancedFilteringWithToolbarComponent
4244 ]
4345 } ) ;
4446 } ) ) ;
@@ -1195,6 +1197,65 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
11951197 } ) ) ;
11961198 } ) ;
11971199
1200+ describe ( 'Advanced filtering with toolbar' , ( ) => {
1201+ let fix : ComponentFixture < IgxGridAdvancedFilteringWithToolbarComponent > ;
1202+ let grid : IgxGridComponent ;
1203+
1204+ beforeEach ( fakeAsync ( ( ) => {
1205+ fix = TestBed . createComponent ( IgxGridAdvancedFilteringWithToolbarComponent ) ;
1206+ grid = fix . componentInstance . grid ;
1207+ fix . detectChanges ( ) ;
1208+ } ) ) ;
1209+
1210+ it ( 'Should update toolbar when advancedFilteringExpressionsTreeChange emits a new value' , fakeAsync ( ( ) => {
1211+ // Set initial filtering expressions tree
1212+ const tree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
1213+ tree . filteringOperands . push ( {
1214+ fieldName : 'ProductName' ,
1215+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
1216+ searchVal : 'angular' ,
1217+ ignoreCase : true
1218+ } ) ;
1219+
1220+ // Apply the initial filtering tree
1221+ grid . advancedFilteringExpressionsTree = tree ;
1222+ fix . detectChanges ( ) ;
1223+
1224+ // Create a new filtering tree with more filters
1225+ const updatedTree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
1226+ updatedTree . filteringOperands . push ( {
1227+ fieldName : 'Downloads' ,
1228+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'equals' ) ,
1229+ searchVal : 10 ,
1230+ ignoreCase : true
1231+ } ) ;
1232+ updatedTree . filteringOperands . push ( {
1233+ fieldName : 'ProductName' ,
1234+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
1235+ searchVal : 'angular' ,
1236+ ignoreCase : true
1237+ } ) ;
1238+ updatedTree . filteringOperands . push ( {
1239+ fieldName : 'Category' ,
1240+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'equals' ) ,
1241+ searchVal : 'electronics' ,
1242+ ignoreCase : false
1243+ } ) ;
1244+
1245+ // Update the filtering expressions tree
1246+ grid . advancedFilteringExpressionsTree = updatedTree ;
1247+ fix . detectChanges ( ) ;
1248+
1249+ // Verify the correct number of filters
1250+ const toolbarDebugElement = fix . debugElement . query ( By . directive ( IgxGridToolbarAdvancedFilteringComponent ) ) ;
1251+ const toolbarComponent = toolbarDebugElement . componentInstance as IgxGridToolbarAdvancedFilteringComponent ;
1252+ const numberOfFilters = ( toolbarComponent as any ) . numberOfColumns ;
1253+
1254+ expect ( grid . advancedFilteringExpressionsTree . filteringOperands . length ) . toEqual ( 3 ) ;
1255+ expect ( numberOfFilters ) . toEqual ( 3 ) ;
1256+ } ) ) ;
1257+ } )
1258+
11981259 describe ( 'Localization - ' , ( ) => {
11991260 it ( 'Should correctly change resource strings for Advanced Filtering dialog.' , fakeAsync ( ( ) => {
12001261 const fix = TestBed . createComponent ( IgxGridAdvancedFilteringComponent ) ;
0 commit comments