Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated structure and added unit/impl tests for pinning #5840

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
}
Loading
Loading