@@ -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,84 @@ 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+ grid . height = '800px' ;
2060+ fixture . detectChanges ( ) ;
2061+ tick ( 50 ) ;
2062+
2063+ expect ( grid . filteredData ) . toBeNull ( ) ;
2064+ expect ( grid . rowList . length ) . toBe ( 8 ) ;
2065+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 0 , 1 ) . value ) . toBe ( 'Ignite UI for JavaScript' ) ;
2066+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 1 , 1 ) . value ) . toBe ( 'NetAdvantage' ) ;
2067+
2068+ // Open Advanced Filtering dialog
2069+ GridFunctions . clickAdvancedFilteringButton ( fixture ) ;
2070+ fixture . detectChanges ( ) ;
2071+
2072+ // Click the initial 'Add And Group' button
2073+ GridFunctions . clickAdvancedFilteringInitialAddGroupButton ( fixture , 0 ) ;
2074+ tick ( 100 ) ;
2075+ fixture . detectChanges ( ) ;
2076+
2077+ // Populate edit inputs
2078+ selectColumnInEditModeExpression ( fixture , 1 ) ;
2079+ selectOperatorInEditModeExpression ( fixture , 2 ) ;
2080+ const input = GridFunctions . getAdvancedFilteringValueInput ( fixture ) . querySelector ( 'input' ) ;
2081+ UIInteractions . clickAndSendInputElementValue ( input , 'ign' , fixture ) ;
2082+
2083+ // Commit the populated expression
2084+ GridFunctions . clickAdvancedFilteringExpressionCommitButton ( fixture ) ;
2085+ fixture . detectChanges ( ) ;
2086+
2087+ // Apply the filters
2088+ GridFunctions . clickAdvancedFilteringApplyButton ( fixture ) ;
2089+ fixture . detectChanges ( ) ;
2090+
2091+ // Verify the filter results
2092+ expect ( grid . filteredData . length ) . toEqual ( 2 ) ;
2093+ expect ( grid . rowList . length ) . toBe ( 2 ) ;
2094+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 0 , 1 ) . value ) . toBe ( 'Ignite UI for JavaScript' ) ;
2095+ expect ( GridFunctions . getCurrentCellFromGrid ( grid , 1 , 1 ) . value ) . toBe ( 'Ignite UI for Angular' ) ;
2096+
2097+ // Change the grid's columns collection
2098+ fixture . componentInstance . columns = [
2099+ { field : 'ID' , header : 'ID' , width : '200px' , type : 'string' } ,
2100+ { field : 'CompanyName' , header : 'Company Name' , width : '200px' , type : 'string' } ,
2101+ { field : 'ContactName' , header : 'Contact Name' , width : '200px' , type : 'string' } ,
2102+ { field : 'ContactTitle' , header : 'Contact Title' , width : '200px' , type : 'string' } ,
2103+ { field : 'City' , header : 'City' , width : '200px' , type : 'string' } ,
2104+ { field : 'Country' , header : 'Country' , width : '200px' , type : 'string' } ,
2105+ ] ;
2106+ fixture . detectChanges ( ) ;
2107+ flush ( ) ;
2108+
2109+ // Change the grid's data collection
2110+ setTimeout ( ( ) => {
2111+ grid . data = SampleTestData . contactInfoDataFull ( ) ;
2112+ fixture . detectChanges ( ) ;
2113+ flush ( ) ;
2114+ } ) ;
2115+
2116+ // Spy for error messages in the console
2117+ const consoleSpy = spyOn ( console , 'error' ) ;
2118+
2119+ // Open Advanced Filtering dialog
2120+ GridFunctions . clickAdvancedFilteringButton ( fixture ) ;
2121+ fixture . detectChanges ( ) ;
2122+ flush ( ) ;
2123+
2124+ // Verify the filters are cleared
2125+ expect ( grid . filteredData ) . toEqual ( [ ] ) ;
2126+ expect ( grid . rowList . length ) . toBe ( 0 ) ;
2127+
2128+ // Check for error messages in the console
2129+ expect ( consoleSpy ) . not . toHaveBeenCalled ( ) ;
2130+ } ) ) ;
2131+
20512132 describe ( 'Context Menu - ' , ( ) => {
20522133 it ( 'Should discard added group when clicking its operator line without having a single expression.' , fakeAsync ( ( ) => {
20532134 // Open Advanced Filtering dialog.
0 commit comments