Skip to content

Commit 2860b8b

Browse files
authored
chore: updated structure and added unit/impl tests for pinning (#5840)
* feat: updated structure and added unit/impl tests for pinning * fix: cleanup test
1 parent fb96ac8 commit 2860b8b

File tree

12 files changed

+1118
-290
lines changed

12 files changed

+1118
-290
lines changed

packages/table-core/tests/RowPinning.test.ts

Lines changed: 0 additions & 285 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createColumnHelper } from '../../../src'
2+
import type { Person, PersonColumn, PersonKeys } from './types'
3+
4+
export function generateColumns(people: Array<Person>): Array<PersonColumn> {
5+
const columnHelper = createColumnHelper<any, Person>()
6+
const person = people[0]
7+
8+
if (!person) {
9+
return []
10+
}
11+
12+
return Object.keys(person).map((key) => {
13+
const typedKey = key as PersonKeys
14+
15+
return columnHelper.accessor(typedKey, { id: typedKey })
16+
})
17+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { faker } from '@faker-js/faker'
2+
import { createArrayOfNumbers } from '../../helpers/testUtils'
3+
import type { Person } from './types'
4+
5+
function createPerson(): Person {
6+
return {
7+
id: faker.string.uuid(),
8+
firstName: faker.person.firstName(),
9+
lastName: faker.person.lastName(),
10+
age: faker.number.int(40),
11+
visits: faker.number.int(1000),
12+
progress: faker.number.int(100),
13+
status: faker.helpers.arrayElement([
14+
'relationship',
15+
'complicated',
16+
'single',
17+
]),
18+
}
19+
}
20+
21+
/**
22+
* Creates a nested array of test Person objects
23+
* @param lengths - An array of numbers where each number determines the length of Person arrays at that depth.
24+
* e.g. makeData(3, 2) creates 3 parent rows with 2 sub-rows each
25+
* @returns An array of Person objects with optional nested subRows based on the provided lengths
26+
*/
27+
export function makeData(...lengths: Array<number>) {
28+
const makeDataLevel = (depth = 0): Array<Person> => {
29+
const len = lengths[depth]
30+
31+
if (!len) return []
32+
33+
return createArrayOfNumbers(len).map(() => {
34+
return {
35+
...createPerson(),
36+
subRows: lengths[depth + 1] ? makeDataLevel(depth + 1) : undefined,
37+
}
38+
})
39+
}
40+
41+
return makeDataLevel()
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { ColumnDef } from '../../../src'
2+
3+
export type PersonKeys = keyof Person
4+
export type PersonColumn = ColumnDef<any, Person, any>
5+
6+
export type Person = {
7+
id: string
8+
firstName: string
9+
lastName: string
10+
age: number
11+
visits: number
12+
progress: number
13+
status: 'relationship' | 'complicated' | 'single'
14+
subRows?: Array<Person>
15+
}

0 commit comments

Comments
 (0)