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