|
| 1 | +import 'react-native'; |
| 2 | +import React from 'react'; |
| 3 | +import Table from '../lib/Table'; |
| 4 | +import { render } from '@testing-library/react-native'; |
| 5 | +import { toObject } from '../utils'; |
| 6 | + |
| 7 | +describe('Table', () => { |
| 8 | + it('columns', () => { |
| 9 | + const columns = [ |
| 10 | + { title: '姓名', dataIndex: 'name' }, |
| 11 | + { title: '性别', dataIndex: 'sex' }, |
| 12 | + { title: '地址', dataIndex: 'address' }, |
| 13 | + ]; |
| 14 | + const { getByTestId } = render(<Table columns={columns} data={[]} rowKey="id" />); |
| 15 | + const component = getByTestId('RNE__Table__header'); |
| 16 | + expect(component.props.children).toHaveLength(3); |
| 17 | + }); |
| 18 | + |
| 19 | + it('data', () => { |
| 20 | + const data = [{ id: 1 }, { id: 2 }]; |
| 21 | + const { getByTestId } = render(<Table columns={[]} data={data} rowKey="id" />); |
| 22 | + const component = getByTestId('RNE__Table__body'); |
| 23 | + expect(component.props.children).toHaveLength(2); |
| 24 | + }); |
| 25 | + |
| 26 | + it('no data', () => { |
| 27 | + const { getByText } = render(<Table columns={[]} data={[]} rowKey="id" />); |
| 28 | + expect(getByText('暂无数据...')).toBeTruthy(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('horizontal', () => { |
| 32 | + const { getByTestId } = render(<Table columns={[]} data={[]} rowKey="id" horizontal={false} />); |
| 33 | + const component = getByTestId('RNE__Table__wrap'); |
| 34 | + expect(component.props.horizontal).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + it('style', () => { |
| 38 | + const { getByTestId } = render(<Table columns={[]} data={[]} rowKey="id" style={{ fontSize: 14 }} />); |
| 39 | + const component = getByTestId('RNE__Table__wrap'); |
| 40 | + const styles = toObject(component.props.style); |
| 41 | + expect(styles.fontSize).toBe(14); |
| 42 | + }); |
| 43 | +}); |
0 commit comments