@@ -15,13 +15,15 @@ import {
1515 IgxGridAdvancedFilteringComponent ,
1616 IgxGridExternalAdvancedFilteringComponent ,
1717 IgxGridAdvancedFilteringBindingComponent ,
18- IgxGridAdvancedFilteringOverlaySettingsComponent
18+ IgxGridAdvancedFilteringOverlaySettingsComponent ,
19+ IgxGridAdvancedFilteringDynamicColumnsComponent
1920} from '../../test-utils/grid-samples.spec' ;
2021import { ControlsFunction } from '../../test-utils/controls-functions.spec' ;
2122import { FormattedValuesFilteringStrategy } from '../../data-operations/filtering-strategy' ;
2223import { IgxHierGridExternalAdvancedFilteringComponent } from '../../test-utils/hierarchical-grid-components.spec' ;
2324import { IgxHierarchicalGridComponent } from '../hierarchical-grid/public_api' ;
2425import { IFilteringEventArgs } from '../public_api' ;
26+ import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
2527
2628const ADVANCED_FILTERING_OPERATOR_LINE_AND_CSS_CLASS = 'igx-filter-tree__line--and' ;
2729const ADVANCED_FILTERING_OPERATOR_LINE_OR_CSS_CLASS = 'igx-filter-tree__line--or' ;
@@ -38,7 +40,8 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
3840 IgxGridAdvancedFilteringComponent ,
3941 IgxGridExternalAdvancedFilteringComponent ,
4042 IgxGridAdvancedFilteringBindingComponent ,
41- IgxHierGridExternalAdvancedFilteringComponent
43+ IgxHierGridExternalAdvancedFilteringComponent ,
44+ IgxGridAdvancedFilteringDynamicColumnsComponent
4245 ]
4346 } ) ;
4447 } ) ) ;
@@ -2048,6 +2051,78 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
20482051 expect ( rows . length ) . toEqual ( 1 , 'Wrong filtered rows count' ) ;
20492052 } ) ) ;
20502053
2054+ it ( 'should handle advanced filtering correctly when grid columns and data are dynamically changed' , fakeAsync ( ( ) => {
2055+ const fixture = TestBed . createComponent ( IgxGridAdvancedFilteringDynamicColumnsComponent ) ;
2056+ grid = fixture . componentInstance . grid ;
2057+ fixture . detectChanges ( ) ;
2058+
2059+ expect ( grid . filteredData ) . toBeNull ( ) ;
2060+ expect ( grid . rowList . length ) . toBe ( 8 ) ;
2061+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 0 , 1 ) . value ) . toBe ( 'Ignite UI for JavaScript' ) ;
2062+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 1 , 1 ) . value ) . toBe ( 'NetAdvantage' ) ;
2063+
2064+ // Open Advanced Filtering dialog
2065+ GridFunctions . clickAdvancedFilteringButton ( fixture ) ;
2066+ fixture . detectChanges ( ) ;
2067+
2068+ // Click the initial 'Add And Group' button
2069+ GridFunctions . clickAdvancedFilteringInitialAddGroupButton ( fixture , 0 ) ;
2070+ tick ( 100 ) ;
2071+ fixture . detectChanges ( ) ;
2072+
2073+ // Populate edit inputs
2074+ selectColumnInEditModeExpression ( fixture , 1 ) ;
2075+ selectOperatorInEditModeExpression ( fixture , 2 ) ;
2076+ const input = GridFunctions . getAdvancedFilteringValueInput ( fixture ) . querySelector ( 'input' ) ;
2077+ UIInteractions . clickAndSendInputElementValue ( input , 'ign' , fixture ) ;
2078+
2079+ // Commit the populated expression
2080+ GridFunctions . clickAdvancedFilteringExpressionCommitButton ( fixture ) ;
2081+ fixture . detectChanges ( ) ;
2082+
2083+ // Apply the filters
2084+ GridFunctions . clickAdvancedFilteringApplyButton ( fixture ) ;
2085+ fixture . detectChanges ( ) ;
2086+
2087+ // Verify the filter results
2088+ expect ( grid . filteredData . length ) . toEqual ( 2 ) ;
2089+ expect ( grid . rowList . length ) . toBe ( 2 ) ;
2090+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 0 , 1 ) . value ) . toBe ( 'Ignite UI for JavaScript' ) ;
2091+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 1 , 1 ) . value ) . toBe ( 'Ignite UI for Angular' ) ;
2092+
2093+ // Change the grid's columns collection
2094+ fixture . componentInstance . columns = [
2095+ { field : 'ID' , header : 'ID' , width : '200px' , type : 'string' } ,
2096+ { field : 'CompanyName' , header : 'Company Name' , width : '200px' , type : 'string' } ,
2097+ { field : 'ContactName' , header : 'Contact Name' , width : '200px' , type : 'string' } ,
2098+ { field : 'ContactTitle' , header : 'Contact Title' , width : '200px' , type : 'string' } ,
2099+ { field : 'City' , header : 'City' , width : '200px' , type : 'string' } ,
2100+ { field : 'Country' , header : 'Country' , width : '200px' , type : 'string' } ,
2101+ ] ;
2102+ fixture . detectChanges ( ) ;
2103+ flush ( ) ;
2104+
2105+ // Change the grid's data collection
2106+ grid . data = SampleTestData . contactInfoDataFull ( ) ;
2107+ fixture . detectChanges ( ) ;
2108+ flush ( ) ;
2109+
2110+ // Check for error messages in the console
2111+ const consoleSpy = spyOn ( console , 'error' ) ;
2112+
2113+ // Open Advanced Filtering dialog
2114+ GridFunctions . clickAdvancedFilteringButton ( fixture ) ;
2115+ fixture . detectChanges ( ) ;
2116+ flush ( ) ;
2117+
2118+ // Verify the filters are cleared
2119+ expect ( grid . filteredData ) . toEqual ( [ ] ) ;
2120+ expect ( grid . rowList . length ) . toBe ( 0 ) ;
2121+
2122+ // Check for error messages in the console
2123+ expect ( consoleSpy ) . not . toHaveBeenCalled ( ) ;
2124+ } ) ) ;
2125+
20512126 describe ( 'Context Menu - ' , ( ) => {
20522127 it ( 'Should discard added group when clicking its operator line without having a single expression.' , fakeAsync ( ( ) => {
20532128 // Open Advanced Filtering dialog.
0 commit comments