From 453dc71cb0acba9d848a5d3e25818a491abe12db Mon Sep 17 00:00:00 2001 From: Joel 'Aaron' Cohen Date: Mon, 4 Nov 2024 16:54:31 -0500 Subject: [PATCH] Add failing test showing row is selected with no selectable subRows --- .../table-core/tests/RowSelection.test.ts | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/packages/table-core/tests/RowSelection.test.ts b/packages/table-core/tests/RowSelection.test.ts index 38bdfb7dcb..dc7a53b9e7 100644 --- a/packages/table-core/tests/RowSelection.test.ts +++ b/packages/table-core/tests/RowSelection.test.ts @@ -28,7 +28,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -57,7 +57,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -86,7 +86,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -154,7 +154,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, state: {}, @@ -179,7 +179,35 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, + renderFallbackValue: '', + data, + getSubRows: row => row.subRows, + state: { + rowSelection: {}, + }, + columns, + getCoreRowModel: getCoreRowModel(), + }) + + const firstRow = table.getCoreRowModel().rows[0] + + const result = RowSelection.isSubRowSelected( + firstRow, + table.getState().rowSelection, + table + ) + + expect(result).toEqual(false) + }) + + it('should return false if no sub-rows are selectable', () => { + const data = makeData(3, 2) + const columns = generateColumns(data) + + const table = createTable({ + enableRowSelection: false, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -207,7 +235,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -237,7 +265,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -267,7 +295,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: row => row.index === 0, // only first row is selectable (of 2 sub-rows) - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows, @@ -296,7 +324,7 @@ describe('RowSelection', () => { const table = createTable({ enableRowSelection: true, - onStateChange() {}, + onStateChange() { }, renderFallbackValue: '', data, getSubRows: row => row.subRows,