@@ -12,7 +12,7 @@ import { IgxGridHeaderGroupComponent } from '../grids/headers/grid-header-group.
1212import { SortingDirection } from '../data-operations/sorting-expression.interface' ;
1313import { IgxCheckboxComponent } from '../checkbox/checkbox.component' ;
1414import { UIInteractions , wait } from './ui-interactions.spec' ;
15- import { IgxGridGroupByRowComponent , IgxGridCellComponent , IgxGridRowComponent } from '../grids/grid' ;
15+ import { IgxGridGroupByRowComponent , IgxGridCellComponent , IgxGridRowComponent , IgxColumnComponent } from '../grids/grid' ;
1616import { ControlsFunction } from './controls-functions.spec' ;
1717import { IgxGridExpandableCellComponent } from '../grids/grid/expandable-cell.component' ;
1818
@@ -59,6 +59,9 @@ const FOCUSED_CHECKBOX_CLASS = 'igx-checkbox--focused';
5959const GRID_BODY_CLASS = '.igx-grid__tbody' ;
6060const DISPLAY_CONTAINER = 'igx-display-container' ;
6161const SORT_ICON_CLASS = '.sort-icon' ;
62+ const SELECTED_COLUMN_CLASS = 'igx-grid__th--selected' ;
63+ const HOVERED_COLUMN_CLASS = 'igx-grid__th--selectable' ;
64+ const SELECTED_COLUMN_CELL_CLASS = 'igx-grid__td--column-selected' ;
6265
6366export class GridFunctions {
6467
@@ -839,7 +842,7 @@ export class GridFunctions {
839842 hideIcon . click ( ) ;
840843 }
841844
842- public static getIconFromButton ( iconName : string , component : any , fix : ComponentFixture < any > ) {
845+ public static getIconFromButton ( iconName : string , component : any ) {
843846 const icons = component . querySelectorAll ( 'igx-icon' ) ;
844847 return Array . from ( icons ) . find ( ( sortIcon : any ) => sortIcon . innerText === iconName ) ;
845848 }
@@ -848,35 +851,42 @@ export class GridFunctions {
848851 * Click the sort ascending button in the ESF.
849852 */
850853 public static clickSortAscInExcelStyleFiltering ( fix : ComponentFixture < any > ) {
851- const sortAscIcon : any = this . getIconFromButton ( 'arrow_upwards' , GridFunctions . getExcelFilteringSortComponent ( fix ) , fix ) ;
854+ const sortAscIcon : any = this . getIconFromButton ( 'arrow_upwards' , GridFunctions . getExcelFilteringSortComponent ( fix ) ) ;
852855 sortAscIcon . click ( ) ;
853856 }
854857
858+ /**
859+ * Click the column selection button in the ESF.
860+ */
861+ public static clickColumnSelectionInExcelStyleFiltering ( fix : ComponentFixture < any > ) {
862+ const columnSelectIcon : any = this . getIconFromButton ( 'done' , GridFunctions . getExcelFilteringColumnSelectionContainer ( fix ) ) ;
863+ columnSelectIcon . click ( ) ;
864+ }
865+
855866 /**
856867 * Click the sort descending button in the ESF.
857868 */
858869 public static clickSortDescInExcelStyleFiltering ( fix : ComponentFixture < any > ) {
859- const sortDescIcon : any = this . getIconFromButton ( 'arrow_downwards' , GridFunctions . getExcelFilteringSortComponent ( fix ) , fix ) ;
870+ const sortDescIcon : any = this . getIconFromButton ( 'arrow_downwards' , GridFunctions . getExcelFilteringSortComponent ( fix ) ) ;
860871 sortDescIcon . click ( ) ;
861872 }
862873
863874 /**
864875 * Click the move left button in the ESF.
865876 */
866877 public static clickMoveLeftInExcelStyleFiltering ( fix : ComponentFixture < any > ) {
867- const moveLeftIcon : any = this . getIconFromButton ( 'arrow_back' , GridFunctions . getExcelFilteringMoveComponent ( fix ) , fix ) ;
878+ const moveLeftIcon : any = this . getIconFromButton ( 'arrow_back' , GridFunctions . getExcelFilteringMoveComponent ( fix ) ) ;
868879 moveLeftIcon . click ( ) ;
869880 }
870881
871882 /**
872883 * Click the move right button in the ESF.
873- */
884+ */
874885 public static clickMoveRightInExcelStyleFiltering ( fix : ComponentFixture < any > ) {
875- const moveRightIcon : any = this . getIconFromButton ( 'arrow_forwards' , GridFunctions . getExcelFilteringMoveComponent ( fix ) , fix ) ;
886+ const moveRightIcon : any = this . getIconFromButton ( 'arrow_forwards' , GridFunctions . getExcelFilteringMoveComponent ( fix ) ) ;
876887 moveRightIcon . click ( ) ;
877888 }
878889
879-
880890 public static getExcelFilteringInput ( fix : ComponentFixture < any > , expressionIndex : number = 0 ) : HTMLInputElement {
881891 const expr = GridFunctions . getExcelCustomFilteringDefaultExpressions ( fix ) [ expressionIndex ] ;
882892 return expr . querySelectorAll ( '.igx-input-group__input' ) . item ( 1 ) as HTMLInputElement ;
@@ -913,6 +923,13 @@ export class GridFunctions {
913923 clearIcon . click ( ) ;
914924 }
915925
926+ /**
927+ * returns the filter row debug element.
928+ */
929+ public static getFilterRow ( fix : ComponentFixture < any > ) : DebugElement {
930+ return fix . debugElement . query ( By . css ( FILTER_UI_ROW ) ) ;
931+ }
932+
916933 /**
917934 * Open filtering row for a column.
918935 */
@@ -1029,6 +1046,18 @@ export class GridFunctions {
10291046 } ) ;
10301047 }
10311048
1049+ public static clickColumnHeaderUI ( columnField : string , fix : ComponentFixture < any > , ctrlKey = false , shiftKey = false ) {
1050+ const header = this . getColumnHeader ( columnField , fix ) ;
1051+ header . triggerEventHandler ( 'click' , new MouseEvent ( 'click' , { shiftKey : shiftKey , ctrlKey : ctrlKey } ) ) ;
1052+ fix . detectChanges ( ) ;
1053+ }
1054+
1055+ public static clickColumnGroupHeaderUI ( columnField : string , fix : ComponentFixture < any > , ctrlKey = false , shiftKey = false ) {
1056+ const header = this . getColumnGroupHeaderCell ( columnField , fix ) ;
1057+ header . triggerEventHandler ( 'click' , new MouseEvent ( 'click' , { shiftKey : shiftKey , ctrlKey : ctrlKey } ) ) ;
1058+ fix . detectChanges ( ) ;
1059+ }
1060+
10321061 public static getColumnHeaderByIndex ( fix : ComponentFixture < any > , index : number ) {
10331062 const nativeHeaders = fix . debugElement . queryAll ( By . directive ( IgxGridHeaderComponent ) )
10341063 . map ( ( header ) => header . nativeElement ) ;
@@ -1091,6 +1120,12 @@ export class GridFunctions {
10911120 return excelMenu . querySelector ( 'igx-excel-style-column-moving' ) ;
10921121 }
10931122
1123+ public static getExcelFilteringColumnSelectionContainer ( fix : ComponentFixture < any > , menu = null ) : HTMLElement {
1124+ const excelMenu = menu ? menu : GridFunctions . getExcelStyleFilteringComponent ( fix ) ;
1125+ return excelMenu . querySelector ( '.igx-excel-filter__actions-select' ) ||
1126+ excelMenu . querySelector ( '.igx-excel-filter__actions-selected' ) ;
1127+ }
1128+
10941129 public static getExcelFilteringLoadingIndicator ( fix : ComponentFixture < any > ) {
10951130 const searchComponent = GridFunctions . getExcelStyleSearchComponent ( fix ) ;
10961131 const loadingIndicator = searchComponent . querySelector ( '.igx-excel-filter__loading' ) ;
@@ -1977,7 +2012,6 @@ export class GridSelectionFunctions {
19772012 expect ( selectedCellFromGrid . rowIndex ) . toEqual ( cell . rowIndex ) ;
19782013 }
19792014
1980-
19812015 public static verifyRowSelected ( row , selected = true , hasCheckbox = true ) {
19822016 expect ( row . selected ) . toBe ( selected ) ;
19832017 expect ( row . nativeElement . classList . contains ( ROW_SELECTION_CSS_CLASS ) ) . toBe ( selected ) ;
@@ -2081,4 +2115,46 @@ export class GridSelectionFunctions {
20812115 public static expandRowIsland ( rowNumber = 1 ) {
20822116 ( < any > document . getElementsByClassName ( ICON_CSS_CLASS ) [ rowNumber ] ) . click ( ) ;
20832117 }
2118+
2119+ public static verifyColumnSelected ( column : IgxColumnComponent , selected = true ) {
2120+ expect ( column . selected ) . toEqual ( selected ) ;
2121+ if ( ! column . hidden ) {
2122+ expect ( column . headerCell . elementRef . nativeElement . classList . contains ( SELECTED_COLUMN_CLASS ) ) . toEqual ( selected ) ;
2123+ }
2124+ }
2125+
2126+ public static verifyColumnsSelected ( columns : IgxColumnComponent [ ] , selected = true ) {
2127+ columns . forEach ( c => this . verifyColumnSelected ( c , selected ) ) ;
2128+ }
2129+
2130+ public static verifyColumnGroupSelected ( fixture : ComponentFixture < any > , column : IgxColumnGroupComponent , selected = true ) {
2131+ expect ( column . selected ) . toEqual ( selected ) ;
2132+ const header = GridFunctions . getColumnGroupHeaderCell ( column . header , fixture ) ;
2133+ expect ( header . nativeElement . classList . contains ( SELECTED_COLUMN_CLASS ) ) . toEqual ( selected ) ;
2134+ }
2135+
2136+ public static verifyColumnHeaderHasSelectableClass ( header : DebugElement , hovered = true ) {
2137+ expect ( header . nativeElement . classList . contains ( HOVERED_COLUMN_CLASS ) ) . toEqual ( hovered ) ;
2138+ }
2139+
2140+ public static verifyColumnsHeadersHasSelectableClass ( headers : DebugElement [ ] , hovered = true ) {
2141+ headers . forEach ( header => this . verifyColumnHeaderHasSelectableClass ( header , hovered ) ) ;
2142+ }
2143+
2144+ public static verifyColumnAndCellsSelected ( column : IgxColumnComponent , selected = true ) {
2145+ this . verifyColumnSelected ( column , selected ) ;
2146+ column . cells . forEach ( cell => {
2147+ expect ( cell . nativeElement . classList . contains ( SELECTED_COLUMN_CELL_CLASS ) ) . toEqual ( selected ) ;
2148+ } ) ;
2149+ }
2150+
2151+ public static clickOnColumnToSelect ( column : IgxColumnComponent , ctrlKey = false , shiftKey = false ) {
2152+ const event = {
2153+ shiftKey : shiftKey ,
2154+ ctrlKey : ctrlKey ,
2155+ stopPropagation : ( ) => { }
2156+ } ;
2157+
2158+ column . headerCell . onClick ( event ) ;
2159+ }
20842160}
0 commit comments