11import { fakeAsync , TestBed } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4- import { IgxPivotDateDimension , IgxPivotGridModule } from 'igniteui-angular' ;
4+ import { IgxChipComponent , IgxChipsAreaComponent , IgxPivotDateDimension , IgxPivotGridModule } from 'igniteui-angular' ;
55import { configureTestSuite } from '../../test-utils/configure-suite' ;
66import { GridFunctions , GridSelectionFunctions } from '../../test-utils/grid-functions.spec' ;
77import { IgxPivotGridTestBaseComponent , IgxPivotGridTestComplexHierarchyComponent , IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec' ;
@@ -177,7 +177,7 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
177177
178178 describe ( 'IgxPivotGrid Features #pivotGrid' , ( ) => {
179179 it ( 'should show excel style filtering via dimension chip.' , ( ) => {
180- const excelMenu = GridFunctions . getExcelStyleFilteringComponent ( fixture , 'igx-pivot-grid' ) ;
180+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 1 ] ;
181181 const headerRow = fixture . nativeElement . querySelector ( 'igx-pivot-header-row' ) ;
182182 const rowChip = headerRow . querySelector ( 'igx-chip[id="All"]' ) ;
183183 const filterIcon = rowChip . querySelectorAll ( 'igx-icon' ) [ 2 ] ;
@@ -204,7 +204,7 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
204204 filterIcon . click ( ) ;
205205 fixture . detectChanges ( ) ;
206206
207- const excelMenu = GridFunctions . getExcelStyleFilteringComponent ( fixture , 'igx-pivot-grid' ) ;
207+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 1 ] ;
208208 const checkboxes : any [ ] = Array . from ( GridFunctions . getExcelStyleFilteringCheckboxes ( fixture , excelMenu , 'igx-pivot-grid' ) ) ;
209209
210210 // uncheck Accessories
@@ -234,7 +234,7 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
234234 const filterIcon = rowChip . querySelectorAll ( 'igx-icon' ) [ 2 ] ;
235235 filterIcon . click ( ) ;
236236 fixture . detectChanges ( ) ;
237- const excelMenu = GridFunctions . getExcelStyleFilteringComponent ( fixture , 'igx-pivot-grid' ) ;
237+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 1 ] ;
238238 const checkboxes : any [ ] = Array . from ( GridFunctions . getExcelStyleFilteringCheckboxes ( fixture , excelMenu , 'igx-pivot-grid' ) ) ;
239239
240240 // uncheck Bulgaria
@@ -256,6 +256,137 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
256256 expect ( colHeaders ) . toEqual ( expected ) ;
257257 } ) ;
258258
259+ it ( 'should show filters chips' , ( ) => {
260+ const pivotGrid = fixture . componentInstance . pivotGrid ;
261+ pivotGrid . pivotConfiguration . filters = [ {
262+ memberName : 'SellerName' ,
263+ enabled : true
264+ } ] ;
265+ pivotGrid . pipeTrigger ++ ;
266+ pivotGrid . setupColumns ( ) ;
267+ fixture . detectChanges ( ) ;
268+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 1 ] ;
269+ const headerRow = fixture . nativeElement . querySelector ( 'igx-pivot-header-row' ) ;
270+ const filtersChip = headerRow . querySelector ( 'igx-chip[id="SellerName"]' ) ;
271+ const filterIcon = filtersChip . querySelectorAll ( 'igx-icon' ) [ 1 ] ;
272+
273+ expect ( excelMenu . parentElement . parentElement . attributes . hidden ) . not . toBeUndefined ( ) ;
274+ filterIcon . click ( ) ;
275+ fixture . detectChanges ( ) ;
276+ const esfSearch = GridFunctions . getExcelFilteringSearchComponent ( fixture , excelMenu , 'igx-pivot-grid' ) ;
277+ const checkBoxes = esfSearch . querySelectorAll ( 'igx-checkbox' ) ;
278+ // should show and should display correct checkboxes.
279+ expect ( excelMenu . parentElement . parentElement . attributes . hidden ) . toBeUndefined ( ) ;
280+ expect ( ( checkBoxes [ 0 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Select All' ) ;
281+ expect ( ( checkBoxes [ 1 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'David' ) ;
282+ expect ( ( checkBoxes [ 2 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Elisa' ) ;
283+ expect ( ( checkBoxes [ 3 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'John' ) ;
284+ expect ( ( checkBoxes [ 4 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Larry' ) ;
285+ } ) ;
286+
287+ it ( 'should show filters in chips dropdown button' , ( ) => {
288+ const pivotGrid = fixture . componentInstance . pivotGrid ;
289+ pivotGrid . pivotConfiguration . filters = [
290+ {
291+ memberName : 'SellerName' ,
292+ enabled : true
293+ } ,
294+ {
295+ memberName : 'ProductCategory' ,
296+ enabled : true
297+ }
298+ ] ;
299+ pivotGrid . pipeTrigger ++ ;
300+ pivotGrid . setupColumns ( ) ;
301+ fixture . detectChanges ( ) ;
302+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 0 ] ;
303+ const headerRow = fixture . nativeElement . querySelector ( 'igx-pivot-header-row' ) ;
304+ const dropdownIcon = headerRow . querySelector ( '.igx-grid__tr-pivot--filter' ) . querySelectorAll ( 'igx-icon' ) [ 0 ] ;
305+
306+ expect ( excelMenu . parentElement . parentElement . attributes . hidden ) . not . toBeUndefined ( ) ;
307+ dropdownIcon . click ( ) ;
308+ fixture . detectChanges ( ) ;
309+
310+ const chips = excelMenu . querySelectorAll ( 'igx-chip' ) ;
311+ expect ( chips [ 0 ] . id ) . toBe ( 'SellerName' ) ;
312+ expect ( chips [ 0 ] . attributes . getNamedItem ( 'ng-reflect-selected' ) . nodeValue ) . toEqual ( 'true' ) ;
313+ expect ( chips [ 1 ] . id ) . toBe ( 'ProductCategory' ) ;
314+ expect ( chips [ 1 ] . attributes . getNamedItem ( 'ng-reflect-selected' ) . nodeValue ) . toEqual ( 'false' ) ;
315+
316+ let esfSearch = GridFunctions . getExcelFilteringSearchComponent ( fixture , excelMenu , 'igx-pivot-grid' ) ;
317+ let checkBoxes = esfSearch . querySelectorAll ( 'igx-checkbox' ) ;
318+ // should show and should display correct checkboxes.
319+ expect ( excelMenu . parentElement . parentElement . attributes . hidden ) . toBeUndefined ( ) ;
320+ expect ( ( checkBoxes [ 0 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Select All' ) ;
321+ expect ( ( checkBoxes [ 1 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'David' ) ;
322+ expect ( ( checkBoxes [ 2 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Elisa' ) ;
323+ expect ( ( checkBoxes [ 3 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'John' ) ;
324+ expect ( ( checkBoxes [ 4 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Larry' ) ;
325+
326+ // switch to the `ProductCategory` filters
327+ const chipAreaElement = fixture . debugElement . queryAll ( By . directive ( IgxChipsAreaComponent ) ) [ 3 ] ;
328+ const chipComponents = chipAreaElement . queryAll ( By . directive ( IgxChipComponent ) ) ;
329+ chipComponents [ 1 ] . triggerEventHandler ( 'chipClick' , {
330+ owner : {
331+ id : chips [ 1 ] . id
332+ }
333+ } ) ;
334+ fixture . detectChanges ( ) ;
335+
336+ esfSearch = GridFunctions . getExcelFilteringSearchComponent ( fixture , excelMenu , 'igx-pivot-grid' ) ;
337+ checkBoxes = esfSearch . querySelectorAll ( 'igx-checkbox' ) ;
338+ expect ( ( checkBoxes [ 0 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Select All' ) ;
339+ expect ( ( checkBoxes [ 1 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Accessories' ) ;
340+ expect ( ( checkBoxes [ 2 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Bikes' ) ;
341+ expect ( ( checkBoxes [ 3 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Clothing' ) ;
342+ expect ( ( checkBoxes [ 4 ] . querySelector ( '.igx-checkbox__label' ) as HTMLElement ) . innerText ) . toEqual ( 'Components' ) ;
343+ } ) ;
344+
345+ it ( 'should be able to filter from chips dropdown button' , ( ) => {
346+ const pivotGrid = fixture . componentInstance . pivotGrid ;
347+ pivotGrid . pivotConfiguration . filters = [
348+ {
349+ memberName : 'SellerName' ,
350+ enabled : true
351+ } ,
352+ {
353+ memberName : 'ProductCategory' ,
354+ enabled : true
355+ }
356+ ] ;
357+ pivotGrid . pipeTrigger ++ ;
358+ pivotGrid . setupColumns ( ) ;
359+ fixture . detectChanges ( ) ;
360+ const excelMenu = GridFunctions . getExcelStyleFilteringComponents ( fixture , 'igx-pivot-grid' ) [ 0 ] ;
361+ const headerRow = fixture . nativeElement . querySelector ( 'igx-pivot-header-row' ) ;
362+ const dropdownIcon = headerRow . querySelector ( '.igx-grid__tr-pivot--filter' ) . querySelectorAll ( 'igx-icon' ) [ 0 ] ;
363+
364+ expect ( excelMenu . parentElement . parentElement . attributes . hidden ) . not . toBeUndefined ( ) ;
365+ dropdownIcon . click ( ) ;
366+ fixture . detectChanges ( ) ;
367+
368+ const checkBoxes : any [ ] = Array . from ( GridFunctions . getExcelStyleFilteringCheckboxes ( fixture , excelMenu , 'igx-pivot-grid' ) ) ;
369+
370+ // uncheck David
371+ checkBoxes [ 1 ] . click ( ) ;
372+ fixture . detectChanges ( ) ;
373+
374+ // uncheck Elisa
375+ checkBoxes [ 5 ] . click ( ) ;
376+ fixture . detectChanges ( ) ;
377+
378+ // Click 'apply' button to apply filter.
379+ GridFunctions . clickApplyExcelStyleFiltering ( fixture , excelMenu , 'igx-pivot-grid' ) ;
380+ fixture . detectChanges ( ) ;
381+
382+ // check rows
383+ const rows = pivotGrid . rowList . toArray ( ) ;
384+ expect ( rows . length ) . toBe ( 3 ) ;
385+ const expectedHeaders = [ 'All' , 'Clothing' , 'Components' ] ;
386+ const rowDimensionHeaders = rows . map ( x => x . rowDimension ) . flat ( ) . map ( x => x . header ) ;
387+ expect ( rowDimensionHeaders ) . toEqual ( expectedHeaders ) ;
388+ } ) ;
389+
259390 it ( 'should apply sorting for dimension via row chip' , ( ) => {
260391 fixture . detectChanges ( ) ;
261392 const pivotGrid = fixture . componentInstance . pivotGrid ;
0 commit comments