-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: updated structure and added unit/impl tests for pinning (#5840)
* feat: updated structure and added unit/impl tests for pinning * fix: cleanup test
- Loading branch information
1 parent
fb96ac8
commit 2860b8b
Showing
12 changed files
with
1,118 additions
and
290 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/table-core/tests/fixtures/data/generateColumns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.