@@ -131,8 +131,8 @@ describe("flattenRowGroups", () => {
131
131
} ;
132
132
const totalRows = 10 ;
133
133
const expected = [
134
- { headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 4 , contentIndex : 0 } ,
135
- { headerIndex : 5 , isCollapsed : true , depth : 0 , path : [ 1 ] , rows : 4 , contentIndex : 4 } ,
134
+ { rowIndex : 0 , headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 4 , contentIndex : 0 } ,
135
+ { rowIndex : 5 , headerIndex : 5 , isCollapsed : true , depth : 0 , path : [ 1 ] , rows : 4 , contentIndex : 4 } ,
136
136
] ;
137
137
const output = flattenRowGroups ( rowGroupingOptions , totalRows ) ;
138
138
expect ( output ) . toEqual ( expected ) ;
@@ -158,9 +158,9 @@ describe("flattenRowGroups", () => {
158
158
} ;
159
159
const totalRows = 10 ;
160
160
const expected = [
161
- { headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 1 , contentIndex : 0 } ,
162
- { headerIndex : 2 , isCollapsed : false , depth : 1 , path : [ 0 , 0 ] , rows : 1 , contentIndex : 1 } ,
163
- { headerIndex : 4 , isCollapsed : true , depth : 1 , path : [ 0 , 1 ] , rows : 1 , contentIndex : 2 } ,
161
+ { rowIndex : 0 , headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 1 , contentIndex : 0 } ,
162
+ { rowIndex : 2 , headerIndex : 2 , isCollapsed : false , depth : 1 , path : [ 0 , 0 ] , rows : 1 , contentIndex : 1 } ,
163
+ { rowIndex : 4 , headerIndex : 4 , isCollapsed : true , depth : 1 , path : [ 0 , 1 ] , rows : 1 , contentIndex : 2 } ,
164
164
] ;
165
165
const output = flattenRowGroups ( rowGroupingOptions , totalRows ) ;
166
166
expect ( output ) . toEqual ( expected ) ;
@@ -183,10 +183,10 @@ describe("flattenRowGroups", () => {
183
183
} ;
184
184
const totalRows = 7 ;
185
185
const expected = [
186
- { headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 0 , contentIndex : 0 } ,
187
- { headerIndex : 1 , isCollapsed : true , depth : 1 , path : [ 0 , 0 ] , rows : 1 , contentIndex : 0 } ,
188
- { headerIndex : 3 , isCollapsed : false , depth : 1 , path : [ 0 , 1 ] , rows : 1 , contentIndex : 1 } ,
189
- { headerIndex : 5 , isCollapsed : true , depth : 0 , path : [ 1 ] , rows : 1 , contentIndex : 2 } ,
186
+ { rowIndex : 0 , headerIndex : 0 , isCollapsed : false , depth : 0 , path : [ 0 ] , rows : 0 , contentIndex : 0 } ,
187
+ { rowIndex : 1 , headerIndex : 1 , isCollapsed : true , depth : 1 , path : [ 0 , 0 ] , rows : 1 , contentIndex : 0 } ,
188
+ { rowIndex : 2 , headerIndex : 3 , isCollapsed : false , depth : 1 , path : [ 0 , 1 ] , rows : 1 , contentIndex : 1 } ,
189
+ { rowIndex : 4 , headerIndex : 5 , isCollapsed : true , depth : 0 , path : [ 1 ] , rows : 1 , contentIndex : 2 } ,
190
190
] ;
191
191
const output = flattenRowGroups ( rowGroupingOptions , totalRows ) ;
192
192
expect ( output ) . toEqual ( expected ) ;
@@ -233,6 +233,125 @@ describe("useRowGroupingInner - getRowThemeOverride", () => {
233
233
const themeOverride = result . current . getRowThemeOverride ?.( 1 ) ;
234
234
expect ( themeOverride ) . toEqual ( { bgCell : "green" } ) ;
235
235
} ) ;
236
+
237
+ it ( "returns correct theme for non-group-header rows when some groups collapsed according to getRowThemeOverrideIn" , ( ) => {
238
+ const rowGroupingOptions = {
239
+ groups : [
240
+ { headerIndex : 0 , isCollapsed : false } ,
241
+ { headerIndex : 3 , isCollapsed : true } ,
242
+ { headerIndex : 5 , isCollapsed : false } ,
243
+ ] ,
244
+ height : 30 ,
245
+ } ;
246
+
247
+ // eslint-disable-next-line unicorn/consistent-function-scoping
248
+ const getRowThemeOverrideIn = ( row : number ) => ( { bgCell : row % 2 === 0 ? "blue" : "green" } ) ;
249
+
250
+ const { result } = renderHook ( ( ) => useRowGroupingInner ( rowGroupingOptions , 10 , 20 , getRowThemeOverrideIn ) ) ;
251
+
252
+ const getRowThemeOverride = result . current . getRowThemeOverride ;
253
+
254
+ // Assuming row 1 is not a group header
255
+ expect ( getRowThemeOverride ?.( 1 ) ) . toEqual ( { bgCell : "green" } ) ;
256
+ expect ( getRowThemeOverride ?.( 2 ) ) . toEqual ( { bgCell : "blue" } ) ;
257
+ expect ( getRowThemeOverride ?.( 5 ) ) . toEqual ( { bgCell : "green" } ) ;
258
+ } ) ;
259
+ } ) ;
260
+
261
+ describe ( "useRowGroupingInner - rowHeight" , ( ) => {
262
+ afterEach ( async ( ) => {
263
+ await cleanup ( ) ;
264
+ } ) ;
265
+
266
+ it ( "applies provided group row height for group headers" , ( ) => {
267
+ const rowGroupingOptions : RowGroupingOptions = {
268
+ groups : [
269
+ { headerIndex : 0 , isCollapsed : false } ,
270
+ { headerIndex : 3 , isCollapsed : false } ,
271
+ { headerIndex : 5 , isCollapsed : false } ,
272
+ ] ,
273
+ height : 30 ,
274
+ } ;
275
+
276
+ const { result } = renderHook ( ( ) => useRowGroupingInner ( rowGroupingOptions , 5 , 20 , undefined ) ) ;
277
+
278
+ expect ( typeof result . current . rowHeight ) . toBe ( "function" ) ;
279
+
280
+ // Assuming row 1 is not a group header
281
+ const rowHeightFn = result . current . rowHeight as ( row : number ) => number ;
282
+ expect ( rowHeightFn ( 0 ) ) . toEqual ( rowGroupingOptions . height ) ;
283
+ expect ( rowHeightFn ( 3 ) ) . toEqual ( rowGroupingOptions . height ) ;
284
+ expect ( rowHeightFn ( 5 ) ) . toEqual ( rowGroupingOptions . height ) ;
285
+ } ) ;
286
+
287
+ it ( "applies provided group row height for group headers when some are collapsed" , ( ) => {
288
+ const rowGroupingOptions : RowGroupingOptions = {
289
+ groups : [
290
+ { headerIndex : 0 , isCollapsed : false } ,
291
+ { headerIndex : 3 , isCollapsed : true } ,
292
+ { headerIndex : 5 , isCollapsed : false } ,
293
+ ] ,
294
+ height : 30 ,
295
+ } ;
296
+
297
+ const { result } = renderHook ( ( ) => useRowGroupingInner ( rowGroupingOptions , 5 , 20 , undefined ) ) ;
298
+
299
+ expect ( typeof result . current . rowHeight ) . toBe ( "function" ) ;
300
+
301
+ // Assuming row 1 is not a group header
302
+ const rowHeightFn = result . current . rowHeight as ( row : number ) => number ;
303
+ expect ( rowHeightFn ( 0 ) ) . toEqual ( rowGroupingOptions . height ) ;
304
+ expect ( rowHeightFn ( 3 ) ) . toEqual ( rowGroupingOptions . height ) ;
305
+ expect ( rowHeightFn ( 4 ) ) . toEqual ( rowGroupingOptions . height ) ;
306
+ } ) ;
307
+
308
+ it ( "returns correct height for non-group-header rows" , ( ) => {
309
+ const rowGroupingOptions = {
310
+ groups : [
311
+ { headerIndex : 0 , isCollapsed : false } ,
312
+ { headerIndex : 3 , isCollapsed : false } ,
313
+ { headerIndex : 5 , isCollapsed : false } ,
314
+ ] ,
315
+ height : 30 ,
316
+ } ;
317
+
318
+ // eslint-disable-next-line unicorn/consistent-function-scoping
319
+ const getRowHeightIn = ( row : number ) => ( row % 2 === 0 ? 20 : 40 ) ;
320
+
321
+ const { result } = renderHook ( ( ) => useRowGroupingInner ( rowGroupingOptions , 10 , getRowHeightIn , undefined ) ) ;
322
+
323
+ expect ( typeof result . current . rowHeight ) . toBe ( "function" ) ;
324
+ const rowHeightFn = result . current . rowHeight as ( row : number ) => number ;
325
+
326
+ // Assuming row 1 is not a group header
327
+ expect ( rowHeightFn ( 1 ) ) . toEqual ( 40 ) ;
328
+ expect ( rowHeightFn ( 2 ) ) . toEqual ( 20 ) ;
329
+ expect ( rowHeightFn ( 5 ) ) . toEqual ( rowGroupingOptions . height ) ;
330
+ } ) ;
331
+
332
+ it ( "returns correct height for non-group-header rows when some groups collapsed" , ( ) => {
333
+ const rowGroupingOptions = {
334
+ groups : [
335
+ { headerIndex : 0 , isCollapsed : false } ,
336
+ { headerIndex : 3 , isCollapsed : true } ,
337
+ { headerIndex : 5 , isCollapsed : false } ,
338
+ ] ,
339
+ height : 30 ,
340
+ } ;
341
+
342
+ // eslint-disable-next-line unicorn/consistent-function-scoping
343
+ const getRowHeightIn = ( row : number ) => ( row % 2 === 0 ? 20 : 40 ) ;
344
+
345
+ const { result } = renderHook ( ( ) => useRowGroupingInner ( rowGroupingOptions , 10 , getRowHeightIn , undefined ) ) ;
346
+
347
+ expect ( typeof result . current . rowHeight ) . toBe ( "function" ) ;
348
+ const rowHeightFn = result . current . rowHeight as ( row : number ) => number ;
349
+
350
+ // Assuming row 1 is not a group header
351
+ expect ( rowHeightFn ( 1 ) ) . toEqual ( 40 ) ;
352
+ expect ( rowHeightFn ( 2 ) ) . toEqual ( 20 ) ;
353
+ expect ( rowHeightFn ( 5 ) ) . toEqual ( 40 ) ; // this will be the first row of the third group
354
+ } ) ;
236
355
} ) ;
237
356
238
357
describe ( "useRowGroupingInner - rows" , ( ) => {
0 commit comments