@@ -28,7 +28,7 @@ import { IgxGridComponent } from './grid.component';
28
28
import { DropPosition } from '../moving/moving.service' ;
29
29
import { clearGridSubs , setupGridScrollDetection } from '../../test-utils/helper-utils.spec' ;
30
30
import { SortingDirection } from '../../data-operations/sorting-strategy' ;
31
- import { IPinningConfig } from '../public_api' ;
31
+ import { IgxGridHeaderRowComponent , IPinningConfig } from '../public_api' ;
32
32
33
33
describe ( 'IgxGrid - Column Pinning #grid' , ( ) => {
34
34
@@ -134,7 +134,7 @@ describe('IgxGrid - Column Pinning #grid', () => {
134
134
expect ( GridFunctions . isCellPinned ( cell ) ) . toBe ( true ) ;
135
135
} ) ;
136
136
137
- it ( 'should allow pinning/unpinning via the column API' , ( ) => {
137
+ it ( 'should allow pinning/unpinning via the column API' , ( ) => {
138
138
const col = grid . getColumnByName ( 'ID' ) ;
139
139
140
140
col . pinned = true ;
@@ -694,9 +694,14 @@ describe('IgxGrid - Column Pinning #grid', () => {
694
694
expect ( grid . getColumnByName ( 'CompanyName' ) . isFirstPinned ) . toBeTruthy ( ) ;
695
695
const row = grid . gridAPI . get_row_by_index ( 0 ) . nativeElement ;
696
696
// 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 ;
697
700
for ( let i = 0 ; i <= pinnedCols . length - 1 ; i ++ ) {
698
701
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 ;
700
705
}
701
706
702
707
// check correct headers have left border
@@ -715,9 +720,13 @@ describe('IgxGrid - Column Pinning #grid', () => {
715
720
const row = grid . gridAPI . get_row_by_index ( 0 ) . nativeElement ;
716
721
expect ( GridFunctions . getRowDisplayContainer ( fix , 0 ) ) . toBeTruthy ( ) ;
717
722
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
+
718
727
expect ( row . children [ 1 ] . classList . contains ( `${ CELL_PINNED_CLASS } -first` ) ) . toBeTruthy ( ) ;
719
728
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 ) ;
721
730
722
731
// check correct headers have left border
723
732
const firstPinnedHeader = grid . headerGroupsList . find ( group => group . isPinned ) ;
@@ -854,10 +863,10 @@ describe('IgxGrid - Column Pinning #grid', () => {
854
863
expect ( grid . unpinnedColumns [ 1 ] . field ) . toEqual ( 'ID' ) ;
855
864
expect ( grid . getColumnByName ( 'ID' ) . pinned ) . toBeFalsy ( ) ;
856
865
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 ( ) ;
861
870
862
871
// verify column is pinned at the correct place
863
872
expect ( grid . pinnedStartColumns [ 0 ] . field ) . toEqual ( 'ID' ) ;
@@ -887,7 +896,7 @@ describe('IgxGrid - Column Pinning #grid', () => {
887
896
expect ( cellFax . active ) . toBe ( false ) ;
888
897
expect ( cellCompanyName . active ) . toBe ( true ) ;
889
898
890
- // navigate from left pinned area into unpinned and back
899
+ // navigate from left pinned area into unpinned and back
891
900
grid . navigation . activeNode = { row : 0 , column : 0 } ;
892
901
fix . detectChanges ( ) ;
893
902
expect ( grid . getCellByColumn ( 0 , "ContactName" ) . active ) . toBe ( true ) ;
@@ -938,25 +947,33 @@ describe('IgxGrid - Column Pinning #grid', () => {
938
947
expect ( grid . getColumnByName ( 'Country' ) . isFirstPinned ) . toBeTruthy ( ) ;
939
948
expect ( grid . getColumnByName ( 'ContactTitle' ) . isLastPinned ) . toBeTruthy ( ) ;
940
949
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 ++ ) {
943
955
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
945
959
}
946
960
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 -- ) {
949
964
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 ;
951
968
}
952
969
953
970
// check correct headers are pinned and in correct order.
954
971
const pinnedHeaders = grid . headerGroupsList . filter ( group => group . isPinned ) ;
955
972
expect ( pinnedHeaders . length ) . toBe ( 10 ) ;
956
973
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' ] ) ;
960
977
961
978
} ) ;
962
979
0 commit comments