@@ -28,7 +28,7 @@ import { IgxGridComponent } from './grid.component';
2828import { DropPosition } from '../moving/moving.service' ;
2929import { clearGridSubs , setupGridScrollDetection } from '../../test-utils/helper-utils.spec' ;
3030import { SortingDirection } from '../../data-operations/sorting-strategy' ;
31- import { IPinningConfig } from '../public_api' ;
31+ import { IgxGridHeaderRowComponent , IPinningConfig } from '../public_api' ;
3232
3333describe ( 'IgxGrid - Column Pinning #grid' , ( ) => {
3434
@@ -134,7 +134,7 @@ describe('IgxGrid - Column Pinning #grid', () => {
134134 expect ( GridFunctions . isCellPinned ( cell ) ) . toBe ( true ) ;
135135 } ) ;
136136
137- it ( 'should allow pinning/unpinning via the column API' , ( ) => {
137+ it ( 'should allow pinning/unpinning via the column API' , ( ) => {
138138 const col = grid . getColumnByName ( 'ID' ) ;
139139
140140 col . pinned = true ;
@@ -694,9 +694,14 @@ describe('IgxGrid - Column Pinning #grid', () => {
694694 expect ( grid . getColumnByName ( 'CompanyName' ) . isFirstPinned ) . toBeTruthy ( ) ;
695695 const row = grid . gridAPI . get_row_by_index ( 0 ) . nativeElement ;
696696 // check cells are rendered after main display container and have left offset
697+ const headerRowDisplayContainer = fix . debugElement . query ( By . directive ( IgxGridHeaderRowComponent ) ) . nativeElement . querySelector ( ".igx-display-container" ) ;
698+ const displayContainerRect = headerRowDisplayContainer . getBoundingClientRect ( ) ;
699+ let xAxis = displayContainerRect . x + displayContainerRect . width ;
697700 for ( let i = 0 ; i <= pinnedCols . length - 1 ; i ++ ) {
698701 const elem = row . children [ i + 1 ] ;
699- expect ( parseInt ( ( elem as any ) . style . left , 10 ) ) . toBe ( - 330 ) ;
702+ const rect = elem . getBoundingClientRect ( ) ;
703+ expect ( rect . x ) . toBe ( xAxis ) ;
704+ xAxis += rect . width ;
700705 }
701706
702707 // check correct headers have left border
@@ -715,9 +720,13 @@ describe('IgxGrid - Column Pinning #grid', () => {
715720 const row = grid . gridAPI . get_row_by_index ( 0 ) . nativeElement ;
716721 expect ( GridFunctions . getRowDisplayContainer ( fix , 0 ) ) . toBeTruthy ( ) ;
717722
723+ const headerRowdisplayContainer = fix . debugElement . query ( By . directive ( IgxGridHeaderRowComponent ) ) . nativeElement . querySelector ( ".igx-display-container" ) ;
724+ const displayContainerRect = headerRowdisplayContainer . getBoundingClientRect ( ) ;
725+ const xAxis = displayContainerRect . x + displayContainerRect . width ;
726+
718727 expect ( row . children [ 1 ] . classList . contains ( `${ CELL_PINNED_CLASS } -first` ) ) . toBeTruthy ( ) ;
719728 expect ( row . children [ 1 ] . classList . contains ( GRID_MRL_BLOCK ) ) . toBeTruthy ( ) ;
720- expect ( parseInt ( ( row . children [ 1 ] as any ) . style . left , 10 ) ) . toEqual ( - 408 ) ;
729+ expect ( row . children [ 1 ] . getBoundingClientRect ( ) . x ) . toEqual ( xAxis ) ;
721730
722731 // check correct headers have left border
723732 const firstPinnedHeader = grid . headerGroupsList . find ( group => group . isPinned ) ;
@@ -854,10 +863,10 @@ describe('IgxGrid - Column Pinning #grid', () => {
854863 expect ( grid . unpinnedColumns [ 1 ] . field ) . toEqual ( 'ID' ) ;
855864 expect ( grid . getColumnByName ( 'ID' ) . pinned ) . toBeFalsy ( ) ;
856865
857- // move 'ID' column to the left pinned area, before ContractName
858- grid . moveColumn ( grid . getColumnByName ( 'ID' ) , grid . getColumnByName ( 'ContactName' ) , DropPosition . BeforeDropTarget ) ;
859- tick ( ) ;
860- fix . detectChanges ( ) ;
866+ // move 'ID' column to the left pinned area, before ContractName
867+ grid . moveColumn ( grid . getColumnByName ( 'ID' ) , grid . getColumnByName ( 'ContactName' ) , DropPosition . BeforeDropTarget ) ;
868+ tick ( ) ;
869+ fix . detectChanges ( ) ;
861870
862871 // verify column is pinned at the correct place
863872 expect ( grid . pinnedStartColumns [ 0 ] . field ) . toEqual ( 'ID' ) ;
@@ -887,7 +896,7 @@ describe('IgxGrid - Column Pinning #grid', () => {
887896 expect ( cellFax . active ) . toBe ( false ) ;
888897 expect ( cellCompanyName . active ) . toBe ( true ) ;
889898
890- // navigate from left pinned area into unpinned and back
899+ // navigate from left pinned area into unpinned and back
891900 grid . navigation . activeNode = { row : 0 , column : 0 } ;
892901 fix . detectChanges ( ) ;
893902 expect ( grid . getCellByColumn ( 0 , "ContactName" ) . active ) . toBe ( true ) ;
@@ -938,25 +947,33 @@ describe('IgxGrid - Column Pinning #grid', () => {
938947 expect ( grid . getColumnByName ( 'Country' ) . isFirstPinned ) . toBeTruthy ( ) ;
939948 expect ( grid . getColumnByName ( 'ContactTitle' ) . isLastPinned ) . toBeTruthy ( ) ;
940949 const row = grid . gridAPI . get_row_by_index ( 0 ) . nativeElement ;
941- // check pinnedEnd cells are rendered after main display container and have left offset
942- for ( let i = pinnedStart . length ; i <= pinnedStart . length + pinnedEnd . length - 1 ; i ++ ) {
950+ fix . detectChanges ( ) ;
951+ // check pinnedEnd cells are rendered after main display container
952+ const displayContainerBoundingBox = row . querySelector ( 'igx-display-container' ) . getBoundingClientRect ( ) ;
953+ let initialStart = displayContainerBoundingBox . x + displayContainerBoundingBox . width ;
954+ for ( let i = pinnedStart . length ; i <= pinnedStart . length + pinnedEnd . length - 1 ; i ++ ) {
943955 const elem = row . children [ i + 1 ] ;
944- expect ( parseFloat ( ( elem as any ) . style . left ) ) . toBe ( - ( grid . pinnedEndWidth + grid . pinnedStartWidth ) ) ;
956+ const rect = elem . getBoundingClientRect ( ) ;
957+ expect ( rect . x ) . toBe ( initialStart ) ;
958+ initialStart += rect . width
945959 }
946960
947- // check pinnedStart cells are rendered before main display container and have no left offset
948- for ( let i = 0 ; i <= pinnedStart . length - 1 ; i ++ ) {
961+ // check pinnedStart cells are rendered before main display container
962+ initialStart = displayContainerBoundingBox . x ;
963+ for ( let i = pinnedStart . length - 1 ; i >= 0 ; i -- ) {
949964 const elem = row . children [ i ] ;
950- expect ( ( elem as any ) . style . left ) . toBe ( '' ) ;
965+ const rect = elem . getBoundingClientRect ( ) ;
966+ expect ( rect . x + rect . width ) . toBe ( initialStart ) ;
967+ initialStart -= rect . width ;
951968 }
952969
953970 // check correct headers are pinned and in correct order.
954971 const pinnedHeaders = grid . headerGroupsList . filter ( group => group . isPinned ) ;
955972 expect ( pinnedHeaders . length ) . toBe ( 10 ) ;
956973 expect ( pinnedHeaders . map ( x => x . column . header || x . column . field ) )
957- . toEqual ( [ 'General Information' , 'CompanyName' , 'Person Details' ,
958- 'ContactName' , 'ContactTitle' , 'Address Information' ,
959- 'Country' , 'Region' , 'City' , 'Address' ] ) ;
974+ . toEqual ( [ 'General Information' , 'CompanyName' , 'Person Details' ,
975+ 'ContactName' , 'ContactTitle' , 'Address Information' ,
976+ 'Country' , 'Region' , 'City' , 'Address' ] ) ;
960977
961978 } ) ;
962979
0 commit comments