@@ -109,7 +109,15 @@ describe('<DatagridRow />', () => {
109
109
</ RecordContextProvider >
110
110
</ LocationSpy >
111
111
) ;
112
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
112
+ const cell = screen . getByText ( 'hello' ) ;
113
+ const row = cell . closest ( 'tr' ) ;
114
+ if ( ! row ) {
115
+ throw new Error ( 'row not found' ) ;
116
+ }
117
+ expect (
118
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
119
+ ) . toBeTruthy ( ) ;
120
+ fireEvent . click ( row ) ;
113
121
114
122
await waitFor ( ( ) => {
115
123
expect ( spy ) . toHaveBeenCalledWith (
@@ -129,7 +137,16 @@ describe('<DatagridRow />', () => {
129
137
</ RecordContextProvider >
130
138
</ LocationSpy >
131
139
) ;
132
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
140
+ const cell = screen . getByText ( 'hello' ) ;
141
+ const row = cell . closest ( 'tr' ) ;
142
+ if ( ! row ) {
143
+ throw new Error ( 'row not found' ) ;
144
+ }
145
+ expect (
146
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
147
+ ) . toBeTruthy ( ) ;
148
+ fireEvent . click ( row ) ;
149
+
133
150
await waitFor ( ( ) => {
134
151
expect ( spy ) . toHaveBeenCalledWith (
135
152
expect . objectContaining ( { pathname : '/posts/15/show' } )
@@ -150,19 +167,27 @@ describe('<DatagridRow />', () => {
150
167
</ RecordContextProvider >
151
168
) ;
152
169
expect ( screen . queryAllByText ( 'expanded' ) ) . toHaveLength ( 0 ) ;
153
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
170
+ const cell = screen . getByText ( 'hello' ) ;
171
+ const row = cell . closest ( 'tr' ) ;
172
+ if ( ! row ) {
173
+ throw new Error ( 'row not found' ) ;
174
+ }
175
+ expect (
176
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
177
+ ) . toBeTruthy ( ) ;
178
+ fireEvent . click ( row ) ;
154
179
await waitFor ( ( ) => {
155
180
expect ( screen . queryAllByText ( 'expanded' ) ) . toHaveLength ( 1 ) ;
156
181
} ) ;
157
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
182
+ fireEvent . click ( row ) ;
158
183
await waitFor ( ( ) => {
159
184
expect ( screen . queryAllByText ( 'expanded' ) ) . toHaveLength ( 0 ) ;
160
185
} ) ;
161
186
} ) ;
162
187
163
188
it ( "should execute the onToggleItem function if the 'toggleSelection' option is selected" , async ( ) => {
164
189
const onToggleItem = jest . fn ( ) ;
165
- const { getByText } = render (
190
+ render (
166
191
< RecordContextProvider value = { defaultRecord } >
167
192
< DatagridRow
168
193
{ ...defaultProps }
@@ -173,15 +198,23 @@ describe('<DatagridRow />', () => {
173
198
</ DatagridRow >
174
199
</ RecordContextProvider >
175
200
) ;
176
- fireEvent . click ( getByText ( 'hello' ) ) ;
201
+ const cell = screen . getByText ( 'hello' ) ;
202
+ const row = cell . closest ( 'tr' ) ;
203
+ if ( ! row ) {
204
+ throw new Error ( 'row not found' ) ;
205
+ }
206
+ expect (
207
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
208
+ ) . toBeTruthy ( ) ;
209
+ fireEvent . click ( row ) ;
177
210
await waitFor ( ( ) => {
178
211
expect ( onToggleItem . mock . calls . length ) . toEqual ( 1 ) ;
179
212
} ) ;
180
213
} ) ;
181
214
182
215
it ( 'should not execute the onToggleItem function if the row is not selectable' , ( ) => {
183
216
const onToggleItem = jest . fn ( ) ;
184
- const { getByText } = render (
217
+ render (
185
218
< RecordContextProvider value = { defaultRecord } >
186
219
< DatagridRow
187
220
{ ...defaultProps }
@@ -193,7 +226,16 @@ describe('<DatagridRow />', () => {
193
226
</ DatagridRow >
194
227
</ RecordContextProvider >
195
228
) ;
196
- fireEvent . click ( getByText ( 'hello' ) ) ;
229
+ const cell = screen . getByText ( 'hello' ) ;
230
+ const row = cell . closest ( 'tr' ) ;
231
+ if ( ! row ) {
232
+ throw new Error ( 'row not found' ) ;
233
+ }
234
+ // FIXME ideally, the row style shouldn't show a pointer in this case
235
+ expect (
236
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
237
+ ) . toBeTruthy ( ) ;
238
+ fireEvent . click ( row ) ;
197
239
expect ( onToggleItem ) . not . toHaveBeenCalled ( ) ;
198
240
} ) ;
199
241
@@ -209,7 +251,15 @@ describe('<DatagridRow />', () => {
209
251
</ RecordContextProvider >
210
252
</ LocationSpy >
211
253
) ;
212
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
254
+ const cell = screen . getByText ( 'hello' ) ;
255
+ const row = cell . closest ( 'tr' ) ;
256
+ if ( ! row ) {
257
+ throw new Error ( 'row not found' ) ;
258
+ }
259
+ expect (
260
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
261
+ ) . toBeTruthy ( ) ;
262
+ fireEvent . click ( row ) ;
213
263
await waitFor ( ( ) => {
214
264
expect ( spy ) . toHaveBeenCalledWith (
215
265
expect . objectContaining ( { pathname : path } )
@@ -232,7 +282,15 @@ describe('<DatagridRow />', () => {
232
282
</ RecordContextProvider >
233
283
</ LocationSpy >
234
284
) ;
235
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
285
+ const cell = screen . getByText ( 'hello' ) ;
286
+ const row = cell . closest ( 'tr' ) ;
287
+ if ( ! row ) {
288
+ throw new Error ( 'row not found' ) ;
289
+ }
290
+ expect (
291
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
292
+ ) . toBeTruthy ( ) ;
293
+ fireEvent . click ( row ) ;
236
294
await new Promise ( resolve => setTimeout ( resolve ) ) ; // waitFor one tick
237
295
await waitFor ( ( ) => {
238
296
expect ( spy ) . toHaveBeenCalledWith (
@@ -252,7 +310,15 @@ describe('<DatagridRow />', () => {
252
310
</ RecordContextProvider >
253
311
</ LocationSpy >
254
312
) ;
255
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
313
+ const cell = screen . getByText ( 'hello' ) ;
314
+ const row = cell . closest ( 'tr' ) ;
315
+ if ( ! row ) {
316
+ throw new Error ( 'row not found' ) ;
317
+ }
318
+ expect (
319
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
320
+ ) . toBeFalsy ( ) ;
321
+ fireEvent . click ( row ) ;
256
322
expect ( spy ) . toHaveBeenCalledWith (
257
323
expect . objectContaining ( { pathname : '/' } )
258
324
) ;
@@ -269,7 +335,15 @@ describe('<DatagridRow />', () => {
269
335
</ RecordContextProvider >
270
336
</ LocationSpy >
271
337
) ;
272
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
338
+ const cell = screen . getByText ( 'hello' ) ;
339
+ const row = cell . closest ( 'tr' ) ;
340
+ if ( ! row ) {
341
+ throw new Error ( 'row not found' ) ;
342
+ }
343
+ expect (
344
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
345
+ ) . toBeFalsy ( ) ;
346
+ fireEvent . click ( row ) ;
273
347
expect ( spy ) . toHaveBeenCalledWith (
274
348
expect . objectContaining ( { pathname : '/' } )
275
349
) ;
@@ -292,7 +366,15 @@ describe('<DatagridRow />', () => {
292
366
</ ResourceDefinitionContextProvider >
293
367
</ LocationSpy >
294
368
) ;
295
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
369
+ const cell = screen . getByText ( 'hello' ) ;
370
+ const row = cell . closest ( 'tr' ) ;
371
+ if ( ! row ) {
372
+ throw new Error ( 'row not found' ) ;
373
+ }
374
+ expect (
375
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
376
+ ) . toBeTruthy ( ) ;
377
+ fireEvent . click ( row ) ;
296
378
await waitFor ( ( ) => {
297
379
expect ( spy ) . toHaveBeenCalledWith (
298
380
expect . objectContaining ( { pathname : '/posts/15' } )
@@ -317,7 +399,15 @@ describe('<DatagridRow />', () => {
317
399
</ ResourceDefinitionContextProvider >
318
400
</ LocationSpy >
319
401
) ;
320
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
402
+ const cell = screen . getByText ( 'hello' ) ;
403
+ const row = cell . closest ( 'tr' ) ;
404
+ if ( ! row ) {
405
+ throw new Error ( 'row not found' ) ;
406
+ }
407
+ expect (
408
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
409
+ ) . toBeTruthy ( ) ;
410
+ fireEvent . click ( row ) ;
321
411
await waitFor ( ( ) => {
322
412
expect ( spy ) . toHaveBeenCalledWith (
323
413
expect . objectContaining ( { pathname : '/posts/15/show' } )
@@ -346,7 +436,15 @@ describe('<DatagridRow />', () => {
346
436
</ ResourceDefinitionContextProvider >
347
437
</ LocationSpy >
348
438
) ;
349
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
439
+ const cell = screen . getByText ( 'hello' ) ;
440
+ const row = cell . closest ( 'tr' ) ;
441
+ if ( ! row ) {
442
+ throw new Error ( 'row not found' ) ;
443
+ }
444
+ expect (
445
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
446
+ ) . toBeTruthy ( ) ;
447
+ fireEvent . click ( row ) ;
350
448
await waitFor ( ( ) => {
351
449
expect ( spy ) . toHaveBeenCalledWith (
352
450
expect . objectContaining ( { pathname : '/posts/15/show' } )
@@ -374,7 +472,15 @@ describe('<DatagridRow />', () => {
374
472
</ ResourceDefinitionContextProvider >
375
473
</ LocationSpy >
376
474
) ;
377
- fireEvent . click ( screen . getByText ( 'hello' ) ) ;
475
+ const cell = screen . getByText ( 'hello' ) ;
476
+ const row = cell . closest ( 'tr' ) ;
477
+ if ( ! row ) {
478
+ throw new Error ( 'row not found' ) ;
479
+ }
480
+ expect (
481
+ row . classList . contains ( 'RaDatagrid-clickableRow' )
482
+ ) . toBeFalsy ( ) ;
483
+ fireEvent . click ( row ) ;
378
484
expect ( spy ) . toHaveBeenCalledWith (
379
485
expect . objectContaining ( { pathname : '/' } )
380
486
) ;
0 commit comments