Skip to content

Commit d556781

Browse files
committed
refactoring as per review suggestions
1 parent cb3246a commit d556781

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/__tests__/use-collection-expadable-rows.test.tsx renamed to src/__tests__/use-collection-expandable-rows.test.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,10 @@ describe('data grouping', () => {
240240
test('computes total counts correctly', () => {
241241
const expandable = renderUseCollection(items, { expandableRows: { getId, getParentId } });
242242
expect(expandable.result.collectionProps.totalItemsCount).toBe(3);
243+
// The getItemsCount is only defined for when data grouping is used.
243244
expect(expandable.result.collectionProps.expandableRows!.getItemsCount).toBe(undefined);
244245

245-
const grouped = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: true } });
246+
const grouped = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: {} } });
246247
expect(grouped.result.collectionProps.totalItemsCount).toBe(3);
247248
expect(grouped.result.collectionProps.expandableRows!.totalItemsCount).toBe(6);
248249
});
@@ -252,31 +253,32 @@ describe('data grouping', () => {
252253
expandableRows: { getId, getParentId },
253254
selection: { defaultSelectedItems: [{ id: 'a' }, { id: 'a.1.1' }], keepSelection: true },
254255
});
256+
// The getSelectedItemsCount is only defined for when data grouping is used.
255257
expect(expandable.result.collectionProps.expandableRows!.getSelectedItemsCount).toBe(undefined);
256258

257259
const grouped = renderUseCollection(items, {
258-
expandableRows: { getId, getParentId, dataGrouping: true },
260+
expandableRows: { getId, getParentId, dataGrouping: {} },
259261
selection: { defaultSelectedItems: [{ id: 'a' }, { id: 'a.1.1' }], keepSelection: true },
260262
});
261263
expect(grouped.result.collectionProps.expandableRows!.totalSelectedItemsCount).toBe(1);
262264
});
263265

264266
test('can call selection counts on missing items', () => {
265267
const { result } = renderUseCollection(items, {
266-
expandableRows: { getId, getParentId, dataGrouping: true },
268+
expandableRows: { getId, getParentId, dataGrouping: {} },
267269
selection: {},
268270
});
269271
expect(result.collectionProps.expandableRows!.getItemsCount!({ id: 'x' })).toBe(0);
270272
expect(result.collectionProps.expandableRows!.getSelectedItemsCount!({ id: 'x' })).toBe(0);
271273
});
272274

273275
test('does not return per-item selection counts when selection=undefined', () => {
274-
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: true } });
276+
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: {} } });
275277
expect(result.collectionProps.expandableRows!.getSelectedItemsCount).toBe(undefined);
276278
});
277279

278280
test('computes item counts correctly', () => {
279-
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: true } });
281+
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: {} } });
280282
const expandableRows = result.collectionProps.expandableRows!;
281283

282284
expect(expandableRows.getItemsCount!({ id: 'a' })).toBe(2);
@@ -289,7 +291,7 @@ describe('data grouping', () => {
289291
for (let totalItems = 0; totalItems <= 25; totalItems += 1) {
290292
const items = generateRandomNestedItems({ totalItems });
291293
const { result } = renderUseCollection(items, {
292-
expandableRows: { getId, getParentId, dataGrouping: true },
294+
expandableRows: { getId, getParentId, dataGrouping: {} },
293295
});
294296
const expandableRows = result.collectionProps.expandableRows!;
295297
const sumCounts = result.items.reduce((sum, i) => sum + expandableRows.getItemsCount!(i), 0);
@@ -299,7 +301,7 @@ describe('data grouping', () => {
299301

300302
test('computes selected item counts correctly', () => {
301303
const { result } = renderUseCollection(items, {
302-
expandableRows: { getId, getParentId, dataGrouping: true },
304+
expandableRows: { getId, getParentId, dataGrouping: {} },
303305
selection: { defaultSelectedItems: [{ id: 'a.1.1' }, { id: 'b.1.1' }, { id: 'b.1.2' }] },
304306
});
305307
const expandableRows = result.collectionProps.expandableRows!;
@@ -308,27 +310,27 @@ describe('data grouping', () => {
308310

309311
test('computes projected selectedItems state', () => {
310312
const leaf = renderUseCollection(items, {
311-
expandableRows: { getId, getParentId, dataGrouping: true },
313+
expandableRows: { getId, getParentId, dataGrouping: {} },
312314
selection: { defaultSelectedItems: [{ id: 'a.1.1' }, { id: 'b.1.1' }, { id: 'b.1.2' }] },
313315
});
314316
expect(leaf.result.collectionProps.selectedItems).toEqual([{ id: 'a.1.1' }, { id: 'b.1.1' }, { id: 'b.1.2' }]);
315317

316318
const deep = renderUseCollection(items, {
317-
expandableRows: { getId, getParentId, dataGrouping: true },
319+
expandableRows: { getId, getParentId, dataGrouping: {} },
318320
selection: { defaultSelectedItems: [{ id: 'a' }, { id: 'b' }, { id: 'b.1' }, { id: 'c' }, { id: 'c.1.2' }] },
319321
});
320322
expect(deep.result.collectionProps.selectedItems).toEqual([{ id: 'a.1.1' }, { id: 'a.1.2' }, { id: 'c.1.1' }]);
321323

322324
const missing = renderUseCollection(items, {
323-
expandableRows: { getId, getParentId, dataGrouping: true },
325+
expandableRows: { getId, getParentId, dataGrouping: {} },
324326
selection: { defaultSelectedItems: [{ id: 'x' }] },
325327
});
326328
expect(missing.result.collectionProps.selectedItems).toEqual([]);
327329
});
328330

329331
test('ignores selected items state in favour of projected selected items', () => {
330332
const { result } = renderUseCollection(items, {
331-
expandableRows: { getId, getParentId, dataGrouping: true },
333+
expandableRows: { getId, getParentId, dataGrouping: {} },
332334
selection: { defaultSelectedItems: [{ id: 'a.1.1' }, { id: 'b.1.1' }, { id: 'b.1.2' }] },
333335
});
334336

@@ -343,13 +345,13 @@ describe('data grouping', () => {
343345
});
344346

345347
test('group selection is undefined when selection=undefined', () => {
346-
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: true } });
348+
const { result } = renderUseCollection(items, { expandableRows: { getId, getParentId, dataGrouping: {} } });
347349
expect(result.collectionProps.expandableRows!.groupSelection).toBe(undefined);
348350
});
349351

350352
test('converts default selected items to group selection and back', () => {
351353
const current = renderUseCollection(items, {
352-
expandableRows: { getId, getParentId, dataGrouping: true },
354+
expandableRows: { getId, getParentId, dataGrouping: {} },
353355
selection: { defaultSelectedItems: [{ id: 'a' }, { id: 'a.1.1' }] },
354356
});
355357
expect(current.result.collectionProps.expandableRows!.groupSelection).toEqual({
@@ -366,7 +368,7 @@ describe('data grouping', () => {
366368

367369
test('changes group selection with event handler', () => {
368370
const current = renderUseCollection(items, {
369-
expandableRows: { getId, getParentId, dataGrouping: true },
371+
expandableRows: { getId, getParentId, dataGrouping: {} },
370372
selection: { defaultSelectedItems: [{ id: 'a' }, { id: 'a.1.1' }] },
371373
});
372374
const changeSelection = current.result.collectionProps.expandableRows!.onGroupSelectionChange;

0 commit comments

Comments
 (0)