@@ -75,6 +75,7 @@ function renderTable(tableProps: Partial<TableProps<Instance>>) {
75
75
renderLoaderPending = { ( { item } ) => `[pending] Loader for ${ item ?. name ?? 'TABLE ROOT' } ` }
76
76
renderLoaderLoading = { ( { item } ) => `[loading] Loader for ${ item ?. name ?? 'TABLE ROOT' } ` }
77
77
renderLoaderError = { ( { item } ) => `[error] Loader for ${ item ?. name ?? 'TABLE ROOT' } ` }
78
+ renderLoaderEmpty = { ( { item } ) => `[empty] Loader for ${ item ?. name ?? 'TABLE ROOT' } ` }
78
79
{ ...tableProps }
79
80
/>
80
81
) ;
@@ -141,7 +142,7 @@ describe('Progressive loading', () => {
141
142
] ) ;
142
143
} ) ;
143
144
144
- test . each ( [ 'pending' , 'loading' , 'error' ] as const ) (
145
+ test . each ( [ 'pending' , 'loading' , 'error' , 'empty' ] as const ) (
145
146
'renders loaders with correct level offset for status="%s"' ,
146
147
status => {
147
148
const { table } = renderTable ( {
@@ -189,21 +190,24 @@ describe('Progressive loading', () => {
189
190
expect ( table . findItemsLoaderByItemId ( 'Nested-1.2.2' ) ) . toBe ( null ) ;
190
191
} ) ;
191
192
192
- test . each ( [ 'loading' , 'error' ] as const ) ( 'loader content for status="%s" is announced with aria-live' , status => {
193
- const { table } = renderTable ( {
194
- expandableRows : {
195
- ...defaultExpandableRows ,
196
- expandedItems : [ { name : 'Root-1' } , { name : 'Nested-1.2' } ] ,
197
- } ,
198
- getLoadingStatus : ( ) => status ,
199
- } ) ;
193
+ test . each ( [ 'empty' , 'loading' , 'error' ] as const ) (
194
+ 'loader content for status="%s" is announced with aria-live' ,
195
+ status => {
196
+ const { table } = renderTable ( {
197
+ expandableRows : {
198
+ ...defaultExpandableRows ,
199
+ expandedItems : [ { name : 'Root-1' } , { name : 'Nested-1.2' } ] ,
200
+ } ,
201
+ getLoadingStatus : ( ) => status ,
202
+ } ) ;
200
203
201
- expect ( getAriaLive ( table . findRootItemsLoader ( ) ! ) ) . toBe ( `[${ status } ] Loader for TABLE ROOT` ) ;
202
- expect ( getAriaLive ( table . findItemsLoaderByItemId ( 'Root-1' ) ! ) ) . toBe ( `[${ status } ] Loader for Root-1` ) ;
203
- expect ( getAriaLive ( table . findItemsLoaderByItemId ( 'Nested-1.2' ) ! ) ) . toBe ( `[${ status } ] Loader for Nested-1.2` ) ;
204
- } ) ;
204
+ expect ( getAriaLive ( table . findRootItemsLoader ( ) ! ) ) . toBe ( `[${ status } ] Loader for TABLE ROOT` ) ;
205
+ expect ( getAriaLive ( table . findItemsLoaderByItemId ( 'Root-1' ) ! ) ) . toBe ( `[${ status } ] Loader for Root-1` ) ;
206
+ expect ( getAriaLive ( table . findItemsLoaderByItemId ( 'Nested-1.2' ) ! ) ) . toBe ( `[${ status } ] Loader for Nested-1.2` ) ;
207
+ }
208
+ ) ;
205
209
206
- test . each ( [ 'pending' , 'loading' , 'error' ] as const ) (
210
+ test . each ( [ 'empty' , ' pending', 'loading' , 'error' ] as const ) (
207
211
'warns when table requires a loader but the render function is missing' ,
208
212
status => {
209
213
render (
@@ -214,11 +218,12 @@ describe('Progressive loading', () => {
214
218
renderLoaderPending = { status === 'pending' ? undefined : ( ) => ( { buttonLabel : 'Load more' } ) }
215
219
renderLoaderLoading = { status === 'loading' ? undefined : ( ) => ( { loadingText : 'Loading' } ) }
216
220
renderLoaderError = { status === 'error' ? undefined : ( ) => ( { cellContent : 'Error' } ) }
221
+ renderLoaderEmpty = { status === 'empty' ? undefined : ( ) => ( { cellContent : 'Empty' } ) }
217
222
/>
218
223
) ;
219
224
expect ( warnOnce ) . toHaveBeenCalledWith (
220
225
'Table' ,
221
- 'Must define `renderLoaderPending`, `renderLoaderLoading`, or `renderLoaderError ` when using corresponding loading status.'
226
+ 'Must define `renderLoaderPending`, `renderLoaderLoading`, `renderLoaderError`, or `renderLoaderEmpty ` when using corresponding loading status.'
222
227
) ;
223
228
}
224
229
) ;
@@ -246,25 +251,28 @@ describe('Progressive loading', () => {
246
251
}
247
252
) ;
248
253
249
- test . each ( [ 'loading' , 'error' ] as const ) ( 'loader row with status="%s" is added after empty expanded item' , status => {
250
- const { table } = renderTable ( {
251
- items : [
252
- {
253
- name : 'Root-1' ,
254
- children : [ ] ,
254
+ test . each ( [ 'empty' , 'pending' , 'loading' , 'error' ] as const ) (
255
+ 'loader row with status="%s" is added after empty expanded item' ,
256
+ status => {
257
+ const { table } = renderTable ( {
258
+ items : [
259
+ {
260
+ name : 'Root-1' ,
261
+ children : [ ] ,
262
+ } ,
263
+ ] ,
264
+ expandableRows : {
265
+ ...defaultExpandableRows ,
266
+ expandedItems : [ { name : 'Root-1' } ] ,
255
267
} ,
256
- ] ,
257
- expandableRows : {
258
- ...defaultExpandableRows ,
259
- expandedItems : [ { name : 'Root-1' } ] ,
260
- } ,
261
- getLoadingStatus : ( ) => status ,
262
- } ) ;
268
+ getLoadingStatus : ( ) => status ,
269
+ } ) ;
263
270
264
- expect ( getTextContent ( table . findItemsLoaderByItemId ( 'Root-1' ) ! ) ) . toBe ( `[${ status } ] Loader for Root-1` ) ;
265
- } ) ;
271
+ expect ( getTextContent ( table . findItemsLoaderByItemId ( 'Root-1' ) ! ) ) . toBe ( `[${ status } ] Loader for Root-1` ) ;
272
+ }
273
+ ) ;
266
274
267
- test . each ( [ undefined , 'pending' , ' finished'] as const ) (
275
+ test . each ( [ undefined , 'finished' ] as const ) (
268
276
'loader row with status="%s" is not added after empty expanded item and a warning is shown' ,
269
277
status => {
270
278
const { table } = renderTable ( {
@@ -284,7 +292,7 @@ describe('Progressive loading', () => {
284
292
expect ( table . findItemsLoaderByItemId ( 'Root-1' ) ) . toBe ( null ) ;
285
293
expect ( warnOnce ) . toHaveBeenCalledWith (
286
294
'Table' ,
287
- 'Expanded items without children must have "loading" or "error " loading status.'
295
+ 'Expanded items without children must not have "finished " loading status.'
288
296
) ;
289
297
}
290
298
) ;
0 commit comments