Skip to content

Commit

Permalink
Fix/tanstack v9 feature test fixes (#5837)
Browse files Browse the repository at this point in the history
* fix: updated tsconfig to include test files

* fix: getGroupRowModel tests

* fix: RowPinning.test.ts

* fix: RowSelection tests

* fix: removed uneeded change
  • Loading branch information
will-short authored Dec 19, 2024
1 parent 3c16d7a commit fb96ac8
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 152 deletions.
129 changes: 74 additions & 55 deletions packages/table-core/tests/RowPinning.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
import { describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it } from 'vitest'
import {
ColumnDef,
createColumnHelper,
constructTable,
createCoreRowModel,
coreFeatures,
createColumnHelper,
createPaginatedRowModel,
rowPinningFeature,
rowPaginationFeature,
rowPinningFeature,
} from '../src'
import { makeData, Person } from './makeTestData'
import { makeData } from './makeTestData'
import type { ColumnDef } from '../src'
import type { Person } from './makeTestData'

type personKeys = keyof Person
type PersonColumn = ColumnDef<
any,
Person,
string | number | Person[] | undefined
>
type PersonColumn = ColumnDef<any, Person, any>

function generateColumns(people: Person[]): PersonColumn[] {
function generateColumns(people: Array<Person>): Array<PersonColumn> {
const columnHelper = createColumnHelper<any, Person>()
const person = people[0]

if (!person) {
return []
}

return Object.keys(person).map((key) => {
const typedKey = key as personKeys
return columnHelper.accessor(typedKey, { id: typedKey })
})
}

describe('rowPinningFeature', () => {
let data: Array<Person>
let columns: Array<PersonColumn>
beforeEach(() => {
data = makeData(10)
columns = generateColumns(data)
})

describe('constructTable', () => {
describe('getTopRows', () => {
it('should return pinned rows when keepPinnedRows is true rows are visible', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -46,7 +56,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 0, //pinned rows will be on page 0
pageIndex: 0, // pinned rows will be on page 0
},
rowPinning: {
bottom: [],
Expand All @@ -59,15 +69,16 @@ describe('rowPinningFeature', () => {
const result = table.getTopRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('0')
expect(result[1].id).toBe('1')
expect(result[0]?.id).toBe('0')
expect(result[1]?.id).toBe('1')
})
it('should return pinned rows when keepPinnedRows is true rows are not visible', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -79,7 +90,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 1, //pinned rows will be on page 0
pageIndex: 1, // pinned rows will be on page 0
},
rowPinning: {
bottom: [],
Expand All @@ -92,15 +103,16 @@ describe('rowPinningFeature', () => {
const result = table.getTopRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('0')
expect(result[1].id).toBe('1')
expect(result[0]?.id).toBe('0')
expect(result[1]?.id).toBe('1')
})
it('should return pinned rows when keepPinnedRows is false rows are visible', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -112,7 +124,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 0, //pinned rows will be on page 0
pageIndex: 0, // pinned rows will be on page 0
},
rowPinning: {
bottom: [],
Expand All @@ -125,15 +137,16 @@ describe('rowPinningFeature', () => {
const result = table.getTopRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('0')
expect(result[1].id).toBe('1')
expect(result[0]?.id).toBe('0')
expect(result[1]?.id).toBe('1')
})
it('should not return pinned rows when keepPinnedRows is false and rows are not visible', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -145,7 +158,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 1, //pinned rows will be on page 0, but this is page 1
pageIndex: 1, // pinned rows will be on page 0, but this is page 1
},
rowPinning: {
bottom: [],
Expand All @@ -161,11 +174,12 @@ describe('rowPinningFeature', () => {
})

it('should return correct top rows', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -177,7 +191,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 0, //pinned rows will be on page 0
pageIndex: 0, // pinned rows will be on page 0
},
rowPinning: {
bottom: [],
Expand All @@ -190,15 +204,16 @@ describe('rowPinningFeature', () => {
const result = table.getTopRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('1')
expect(result[1].id).toBe('3')
expect(result[0]?.id).toBe('1')
expect(result[1]?.id).toBe('3')
})
it('should return correct bottom rows', () => {
const data = makeData(10)
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -210,7 +225,7 @@ describe('rowPinningFeature', () => {
state: {
pagination: {
pageSize: 5,
pageIndex: 0, //pinned rows will be on page 0
pageIndex: 0, // pinned rows will be on page 0
},
rowPinning: {
bottom: ['1', '3'],
Expand All @@ -223,8 +238,8 @@ describe('rowPinningFeature', () => {
const result = table.getBottomRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('1')
expect(result[1].id).toBe('3')
expect(result[0]?.id).toBe('1')
expect(result[1]?.id).toBe('3')
})
})
describe('getCenterRows', () => {
Expand All @@ -233,7 +248,11 @@ describe('rowPinningFeature', () => {
const columns = generateColumns(data)

const table = constructTable<any, Person>({
_features: { rowPinningFeature, rowPaginationFeature },
_features: {
rowPinningFeature,
rowPaginationFeature,
...coreFeatures,
},
_rowModels: {
paginatedRowModel: createPaginatedRowModel(),
},
Expand All @@ -258,8 +277,8 @@ describe('rowPinningFeature', () => {
const result = table.getCenterRows()

expect(result.length).toBe(2)
expect(result[0].id).toBe('0') // 0 and 5 are the only rows not pinned
expect(result[1].id).toBe('5')
expect(result[0]?.id).toBe('0') // 0 and 5 are the only rows not pinned
expect(result[1]?.id).toBe('5')
})
})
})
Expand Down
Loading

0 comments on commit fb96ac8

Please sign in to comment.