Skip to content

Commit

Permalink
chore: updated structure and added unit/impl tests for pinning (#5840)
Browse files Browse the repository at this point in the history
* feat: updated structure and added unit/impl tests for pinning

* fix: cleanup test
  • Loading branch information
will-short authored Dec 21, 2024
1 parent fb96ac8 commit 2860b8b
Show file tree
Hide file tree
Showing 12 changed files with 1,118 additions and 290 deletions.
285 changes: 0 additions & 285 deletions packages/table-core/tests/RowPinning.test.ts

This file was deleted.

17 changes: 17 additions & 0 deletions packages/table-core/tests/fixtures/data/generateColumns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createColumnHelper } from '../../../src'
import type { Person, PersonColumn, PersonKeys } from './types'

export 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 })
})
}
42 changes: 42 additions & 0 deletions packages/table-core/tests/fixtures/data/makeData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { faker } from '@faker-js/faker'
import { createArrayOfNumbers } from '../../helpers/testUtils'
import type { Person } from './types'

function createPerson(): Person {
return {
id: faker.string.uuid(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
age: faker.number.int(40),
visits: faker.number.int(1000),
progress: faker.number.int(100),
status: faker.helpers.arrayElement([
'relationship',
'complicated',
'single',
]),
}
}

/**
* Creates a nested array of test Person objects
* @param lengths - An array of numbers where each number determines the length of Person arrays at that depth.
* e.g. makeData(3, 2) creates 3 parent rows with 2 sub-rows each
* @returns An array of Person objects with optional nested subRows based on the provided lengths
*/
export function makeData(...lengths: Array<number>) {
const makeDataLevel = (depth = 0): Array<Person> => {
const len = lengths[depth]

if (!len) return []

return createArrayOfNumbers(len).map(() => {
return {
...createPerson(),
subRows: lengths[depth + 1] ? makeDataLevel(depth + 1) : undefined,
}
})
}

return makeDataLevel()
}
15 changes: 15 additions & 0 deletions packages/table-core/tests/fixtures/data/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ColumnDef } from '../../../src'

export type PersonKeys = keyof Person
export type PersonColumn = ColumnDef<any, Person, any>

export type Person = {
id: string
firstName: string
lastName: string
age: number
visits: number
progress: number
status: 'relationship' | 'complicated' | 'single'
subRows?: Array<Person>
}
File renamed without changes.
Loading

0 comments on commit 2860b8b

Please sign in to comment.