Skip to content

Commit

Permalink
test: BodyCell renders
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmylee committed May 14, 2022
1 parent 9f042f4 commit 726ef88
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/lib/bodyCells.newDataBodyCell.test.ts
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');
});
61 changes: 61 additions & 0 deletions src/lib/bodyCells.newDisplayBodyCell.test.ts
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');
});

0 comments on commit 726ef88

Please sign in to comment.