@@ -1078,20 +1078,23 @@ describe('<DataGrid /> - Rows', () => {
10781078 const border = 1 ;
10791079 const defaultRowHeight = 52 ;
10801080 const measuredRowHeight = 101 ;
1081+ // The virtualizer renders one extra row past the visible viewport (see
1082+ // `getIndexesToRender`), so a single-row viewport measures the first
1083+ // two rows; the rest are left at the default height.
1084+ const measuredRowCount = 2 ;
10811085 render (
10821086 < TestCase
10831087 columnHeaderHeight = { columnHeaderHeight }
1084- height = { columnHeaderHeight + 20 + border * 2 } // Force to only measure the first row
1088+ height = { columnHeaderHeight + 20 + border * 2 }
10851089 getBioContentHeight = { ( ) => measuredRowHeight }
10861090 getRowHeight = { ( ) => 'auto' }
10871091 rowBufferPx = { 0 }
10881092 /> ,
10891093 ) ;
10901094 const element = document . querySelector ( '.MuiDataGrid-contentFiller' ) ;
10911095 const expectedHeight =
1092- measuredRowHeight +
1093- border + // Measured rows also include the border
1094- ( baselineProps . rows . length - 1 ) * defaultRowHeight ;
1096+ measuredRowCount * ( measuredRowHeight + border ) + // Measured rows also include the border
1097+ ( baselineProps . rows . length - measuredRowCount ) * defaultRowHeight ;
10951098
10961099 await waitFor ( ( ) => {
10971100 expect ( element ) . toHaveComputedStyle ( { height : `${ expectedHeight } px` } ) ;
@@ -1103,20 +1106,24 @@ describe('<DataGrid /> - Rows', () => {
11031106 const border = 1 ;
11041107 const measuredRowHeight = 100 ;
11051108 const estimatedRowHeight = 90 ;
1109+ // See `getIndexesToRender` — a single-row viewport still measures the
1110+ // first two rows because of the trailing render-context safety row.
1111+ const measuredRowCount = 2 ;
11061112 render (
11071113 < TestCase
11081114 columnHeaderHeight = { columnHeaderHeight }
1109- height = { columnHeaderHeight + 20 + border * 2 } // Force to only measure the first row
1115+ height = { columnHeaderHeight + 20 + border * 2 }
11101116 getBioContentHeight = { ( ) => measuredRowHeight }
11111117 getEstimatedRowHeight = { ( ) => estimatedRowHeight }
11121118 getRowHeight = { ( ) => 'auto' }
11131119 rowBufferPx = { 0 }
11141120 /> ,
11151121 ) ;
11161122 const element = document . querySelector ( '.MuiDataGrid-contentFiller' ) ;
1117- const firstRowHeight = measuredRowHeight + border ; // Measured rows also include the border
1123+ const measuredHeight = measuredRowHeight + border ; // Measured rows also include the border
11181124 const expectedHeight =
1119- firstRowHeight + ( baselineProps . rows . length - 1 ) * estimatedRowHeight ;
1125+ measuredRowCount * measuredHeight +
1126+ ( baselineProps . rows . length - measuredRowCount ) * estimatedRowHeight ;
11201127
11211128 await waitFor ( ( ) => {
11221129 expect ( element ) . toHaveComputedStyle ( { height : `${ expectedHeight } px` } ) ;
@@ -1187,8 +1194,11 @@ describe('<DataGrid /> - Rows', () => {
11871194 ) ;
11881195 const virtualScroller = grid ( 'virtualScroller' ) ! ;
11891196
1197+ // With one row of viewport, `getIndexesToRender` still renders (and
1198+ // therefore measures) the next row past the visible area, so the first
1199+ // two rows are measured before any scroll happens.
11901200 await waitFor ( ( ) => {
1191- expect ( virtualScroller . scrollHeight ) . to . equal ( columnHeaderHeight + 101 + 52 + 52 ) ;
1201+ expect ( virtualScroller . scrollHeight ) . to . equal ( columnHeaderHeight + 101 + 101 + 52 ) ;
11921202 } ) ;
11931203
11941204 // It calculates the entire height of the scrollbar whenever the scroll event happens
0 commit comments