|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { Rows } from './Rows' |
| 3 | +import { _createRow } from './createRow' |
| 4 | +import type { Row } from '../../types/Row' |
| 5 | +import type { Table } from '../../types/Table' |
| 6 | + |
| 7 | +interface Person { |
| 8 | + firstName: string |
| 9 | +} |
| 10 | + |
| 11 | +describe('createRow', () => { |
| 12 | + it('should create a row with all core row APIs and properties', () => { |
| 13 | + const table = { _features: { Rows }, options: {} } as Table<any, Person> |
| 14 | + const id = 'test-row' |
| 15 | + const original = { firstName: 'Tanner' } as Person |
| 16 | + const rowIndex = 0 |
| 17 | + const depth = 0 |
| 18 | + const subRows = [] as Array<Row<any, Person>> |
| 19 | + const parentId = 'parent-id' |
| 20 | + |
| 21 | + const row = _createRow( |
| 22 | + table, |
| 23 | + id, |
| 24 | + original, |
| 25 | + rowIndex, |
| 26 | + depth, |
| 27 | + subRows, |
| 28 | + parentId, |
| 29 | + ) |
| 30 | + |
| 31 | + expect(row).toBeDefined() |
| 32 | + expect(row).toHaveProperty('_uniqueValuesCache') |
| 33 | + expect(row).toHaveProperty('_valuesCache') |
| 34 | + expect(row).toHaveProperty('depth') |
| 35 | + expect(row).toHaveProperty('id') |
| 36 | + expect(row).toHaveProperty('index') |
| 37 | + expect(row).toHaveProperty('original') |
| 38 | + expect(row).toHaveProperty('parentId') |
| 39 | + expect(row).toHaveProperty('subRows') |
| 40 | + expect(row).toHaveProperty('getAllCellsByColumnId') |
| 41 | + expect(row).toHaveProperty('getAllCells') |
| 42 | + expect(row).toHaveProperty('getLeafRows') |
| 43 | + expect(row).toHaveProperty('getParentRow') |
| 44 | + expect(row).toHaveProperty('getParentRows') |
| 45 | + expect(row).toHaveProperty('getUniqueValues') |
| 46 | + expect(row).toHaveProperty('getValue') |
| 47 | + expect(row).toHaveProperty('renderValue') |
| 48 | + |
| 49 | + expect(row.id).toBe(id) |
| 50 | + expect(row.original).toBe(original) |
| 51 | + expect(row.index).toBe(rowIndex) |
| 52 | + expect(row.depth).toBe(depth) |
| 53 | + expect(row.subRows).toBe(subRows) |
| 54 | + expect(row.parentId).toBe(parentId) |
| 55 | + }) |
| 56 | +}) |
0 commit comments