77 getSelectedCell ,
88 scrollGrid ,
99 setup ,
10+ tabIntoGrid ,
1011 validateCellPosition
1112} from './utils' ;
1213
@@ -27,13 +28,13 @@ const columns = [
2728] as const satisfies Column < Row , Row > [ ] ;
2829
2930test ( 'keyboard navigation' , async ( ) => {
30- setup ( { columns, rows, topSummaryRows, bottomSummaryRows } ) ;
31+ setup ( { columns, rows, topSummaryRows, bottomSummaryRows } , true ) ;
3132
3233 // no initial selection
3334 await expect . element ( getSelectedCell ( ) ) . not . toBeInTheDocument ( ) ;
3435
3536 // tab into the grid
36- await userEvent . tab ( ) ;
37+ await tabIntoGrid ( ) ;
3738 validateCellPosition ( 0 , 0 ) ;
3839
3940 // tab to the next cell
@@ -103,10 +104,10 @@ test('keyboard navigation', async () => {
103104} ) ;
104105
105106test ( 'arrow and tab navigation' , async ( ) => {
106- setup ( { columns, rows, bottomSummaryRows } ) ;
107+ setup ( { columns, rows, bottomSummaryRows } , true ) ;
107108
108109 // pressing arrowleft on the leftmost cell does nothing
109- await userEvent . tab ( ) ;
110+ await tabIntoGrid ( ) ;
110111 await userEvent . keyboard ( '{arrowdown}' ) ;
111112 validateCellPosition ( 0 , 1 ) ;
112113 await userEvent . keyboard ( '{arrowleft}' ) ;
@@ -128,14 +129,7 @@ test('arrow and tab navigation', async () => {
128129} ) ;
129130
130131test ( 'grid enter/exit' , async ( ) => {
131- page . render (
132- < >
133- < button type = "button" > Before</ button >
134- < DataGrid columns = { columns } rows = { new Array ( 5 ) } bottomSummaryRows = { bottomSummaryRows } />
135- < br />
136- < button type = "button" > After</ button >
137- </ >
138- ) ;
132+ setup ( { columns, rows : new Array ( 5 ) , bottomSummaryRows } , true ) ;
139133
140134 const beforeButton = page . getByRole ( 'button' , { name : 'Before' } ) ;
141135 const afterButton = page . getByRole ( 'button' , { name : 'After' } ) ;
@@ -144,8 +138,7 @@ test('grid enter/exit', async () => {
144138 await expect . element ( getSelectedCell ( ) ) . not . toBeInTheDocument ( ) ;
145139
146140 // tab into the grid
147- await userEvent . click ( beforeButton ) ;
148- await userEvent . tab ( ) ;
141+ await tabIntoGrid ( ) ;
149142 validateCellPosition ( 0 , 0 ) ;
150143
151144 // shift+tab tabs out of the grid if we are at the first cell
@@ -178,8 +171,8 @@ test('grid enter/exit', async () => {
178171} ) ;
179172
180173test ( 'navigation with focusable cell renderer' , async ( ) => {
181- setup ( { columns, rows : new Array ( 1 ) , bottomSummaryRows } ) ;
182- await userEvent . tab ( ) ;
174+ setup ( { columns, rows : new Array ( 1 ) , bottomSummaryRows } , true ) ;
175+ await tabIntoGrid ( ) ;
183176 await userEvent . keyboard ( '{arrowdown}' ) ;
184177 validateCellPosition ( 0 , 1 ) ;
185178
@@ -219,8 +212,8 @@ test('navigation when header and summary rows have focusable elements', async ()
219212 }
220213 ] ;
221214
222- setup ( { columns, rows : new Array ( 2 ) , bottomSummaryRows } ) ;
223- await userEvent . tab ( ) ;
215+ setup ( { columns, rows : new Array ( 2 ) , bottomSummaryRows } , true ) ;
216+ await tabIntoGrid ( ) ;
224217
225218 // should set focus on the header filter
226219 expect ( document . getElementById ( 'header-filter1' ) ) . toHaveFocus ( ) ;
@@ -259,8 +252,8 @@ test('navigation when selected cell not in the viewport', async () => {
259252 for ( let i = 0 ; i < 99 ; i ++ ) {
260253 columns . push ( { key : `col${ i } ` , name : `col${ i } ` , frozen : i < 5 } ) ;
261254 }
262- setup ( { columns, rows, bottomSummaryRows } ) ;
263- await userEvent . tab ( ) ;
255+ setup ( { columns, rows, bottomSummaryRows } , true ) ;
256+ await tabIntoGrid ( ) ;
264257 validateCellPosition ( 0 , 0 ) ;
265258
266259 await userEvent . keyboard ( '{Control>}{end}{/Control}{arrowup}{arrowup}' ) ;
@@ -331,8 +324,8 @@ test('reset selected cell when row is removed', async () => {
331324} ) ;
332325
333326test ( 'should not change the left and right arrow behavior for right to left languages' , async ( ) => {
334- setup ( { rows, columns, direction : 'rtl' } ) ;
335- await userEvent . tab ( ) ;
327+ setup ( { rows, columns, direction : 'rtl' } , true ) ;
328+ await tabIntoGrid ( ) ;
336329 validateCellPosition ( 0 , 0 ) ;
337330 await userEvent . tab ( ) ;
338331 validateCellPosition ( 1 , 0 ) ;
0 commit comments