@@ -15,12 +15,13 @@ import {
15
15
IgxGridAdvancedFilteringComponent ,
16
16
IgxGridExternalAdvancedFilteringComponent ,
17
17
IgxGridAdvancedFilteringBindingComponent ,
18
- IgxGridAdvancedFilteringDynamicColumnsComponent
18
+ IgxGridAdvancedFilteringDynamicColumnsComponent ,
19
+ IgxGridAdvancedFilteringWithToolbarComponent
19
20
} from '../../test-utils/grid-samples.spec' ;
20
21
import { FormattedValuesFilteringStrategy } from '../../data-operations/filtering-strategy' ;
21
22
import { IgxHierGridExternalAdvancedFilteringComponent } from '../../test-utils/hierarchical-grid-components.spec' ;
22
23
import { IgxHierarchicalGridComponent } from '../hierarchical-grid/public_api' ;
23
- import { IFilteringEventArgs } from '../public_api' ;
24
+ import { IFilteringEventArgs , IgxGridToolbarAdvancedFilteringComponent } from '../public_api' ;
24
25
import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
25
26
import { QueryBuilderFunctions } from '../../query-builder/query-builder-functions.spec' ;
26
27
import { By } from '@angular/platform-browser' ;
@@ -37,11 +38,12 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
37
38
IgxGridExternalAdvancedFilteringComponent ,
38
39
IgxGridAdvancedFilteringBindingComponent ,
39
40
IgxHierGridExternalAdvancedFilteringComponent ,
40
- IgxGridAdvancedFilteringDynamicColumnsComponent
41
+ IgxGridAdvancedFilteringDynamicColumnsComponent ,
42
+ IgxGridAdvancedFilteringWithToolbarComponent
41
43
]
42
44
} ) ;
43
45
} ) ) ;
44
-
46
+
45
47
describe ( 'General tests - ' , ( ) => {
46
48
let fix : ComponentFixture < IgxGridAdvancedFilteringComponent > ;
47
49
let grid : IgxGridComponent ;
@@ -1194,6 +1196,65 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
1194
1196
} ) ) ;
1195
1197
} ) ;
1196
1198
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
+
1197
1258
describe ( 'Localization - ' , ( ) => {
1198
1259
it ( 'Should correctly change resource strings for Advanced Filtering dialog.' , fakeAsync ( ( ) => {
1199
1260
const fix = TestBed . createComponent ( IgxGridAdvancedFilteringComponent ) ;
@@ -1225,11 +1286,11 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
1225
1286
tick ( 100 ) ;
1226
1287
fix . detectChanges ( ) ;
1227
1288
1228
-
1289
+
1229
1290
// Populate edit inputs.
1230
1291
QueryBuilderFunctions . selectColumnInEditModeExpression ( fix , 1 ) ; // Select 'ProductName' column.
1231
1292
QueryBuilderFunctions . selectOperatorInEditModeExpression ( fix , 0 ) ; // Select 'Contains' operator.
1232
-
1293
+
1233
1294
let input = QueryBuilderFunctions . getQueryBuilderValueInput ( fix ) . querySelector ( 'input' ) ;
1234
1295
UIInteractions . clickAndSendInputElementValue ( input , 'angular' , fix ) ; // Type filter value.
1235
1296
// Commit the populated expression.
@@ -1278,7 +1339,7 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
1278
1339
grid = fix . componentInstance . grid ;
1279
1340
fix . detectChanges ( ) ;
1280
1341
} ) ) ;
1281
-
1342
+
1282
1343
it ( 'Should allow hosting Advanced Filtering dialog outside of the grid.' , fakeAsync ( ( ) => {
1283
1344
// Add a root 'and' group.
1284
1345
QueryBuilderFunctions . clickQueryBuilderInitialAddConditionBtn ( fix , 0 ) ;
0 commit comments