-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f042f4
commit 726ef88
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
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,54 @@ | ||
import { DataBodyCell } from './bodyCells'; | ||
import { BodyRow } from './bodyRows'; | ||
import { DataColumn } from './columns'; | ||
|
||
interface User { | ||
firstName: string; | ||
lastName: string; | ||
age: number; | ||
visits: number; | ||
progress: number; | ||
status: string; | ||
} | ||
|
||
const user: User = { | ||
firstName: 'Adam', | ||
lastName: 'Smith', | ||
age: 43, | ||
visits: 2, | ||
progress: 50, | ||
status: 'complicated', | ||
}; | ||
|
||
const row = new BodyRow({ | ||
id: '0', | ||
original: user, | ||
cells: [], | ||
cellForId: {}, | ||
}); | ||
|
||
const column = new DataColumn({ | ||
header: '', | ||
accessor: 'firstName', | ||
}); | ||
|
||
it('renders without label', () => { | ||
const actual = new DataBodyCell<User>({ | ||
column, | ||
row, | ||
value: 'Adam', | ||
}); | ||
|
||
expect(actual.render()).toBe('Adam'); | ||
}); | ||
|
||
it('renders with label', () => { | ||
const actual = new DataBodyCell<User>({ | ||
column, | ||
row, | ||
value: 'Adam', | ||
label: (value) => String(value).toLowerCase(), | ||
}); | ||
|
||
expect(actual.render()).toBe('adam'); | ||
}); |
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,61 @@ | ||
import { DisplayBodyCell } from './bodyCells'; | ||
import { BodyRow } from './bodyRows'; | ||
import { DisplayColumn } from './columns'; | ||
import type { TableState } from './createViewModel'; | ||
|
||
interface User { | ||
firstName: string; | ||
lastName: string; | ||
age: number; | ||
visits: number; | ||
progress: number; | ||
status: string; | ||
} | ||
|
||
const user: User = { | ||
firstName: 'Adam', | ||
lastName: 'Smith', | ||
age: 43, | ||
visits: 2, | ||
progress: 50, | ||
status: 'complicated', | ||
}; | ||
|
||
const row = new BodyRow({ | ||
id: '0', | ||
original: user, | ||
cells: [], | ||
cellForId: {}, | ||
}); | ||
|
||
const column = new DisplayColumn({ | ||
header: '', | ||
cell: () => '', | ||
id: 'checked', | ||
}); | ||
|
||
const state = {} as TableState<User>; | ||
|
||
it('renders label with state', () => { | ||
const actual = new DisplayBodyCell<User>({ | ||
column, | ||
row, | ||
label: (rowId) => `row ${rowId} checked`, | ||
}); | ||
|
||
actual.injectState(state); | ||
|
||
expect(actual.render()).toBe('row 0 checked'); | ||
}); | ||
|
||
it('throws if rendering without state', () => { | ||
const actual = new DisplayBodyCell<User>({ | ||
column, | ||
row, | ||
label: (rowId) => `row ${rowId} checked`, | ||
}); | ||
|
||
expect(() => { | ||
actual.render(); | ||
}).toThrowError('Missing `state` reference'); | ||
}); |