Don't ignore test files.

This commit is contained in:
Wei Zhu 2016-12-14 14:48:09 +08:00
parent 17a0a33283
commit 07103b9fb6
64 changed files with 995 additions and 0 deletions

1
.gitignore vendored
View File

@ -31,3 +31,4 @@ components/**/*.js
components/**/*.jsx
/.vscode/
/coverage
!components/**/__tests__/*

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('affix');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('alert');

View File

@ -0,0 +1,20 @@
import React from 'react';
import { mount } from 'enzyme';
import Anchor from '..';
const { Link } = Anchor;
describe('Anchor Render', () => {
it('Anchor render perfectly', () => {
const wrapper = mount(
<Anchor>
<Link href="#API" title="API" />
</Anchor>
);
wrapper.find('a[href="#API"]').simulate('click');
wrapper.node.handleScroll();
expect(wrapper.node.state).not.toBe(null);
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('anchor');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('auto-complete');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('back-top');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('badge');

View File

@ -0,0 +1,12 @@
import { render } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import demoTest from '../../../tests/shared/demoTest';
import routerDemo from '../demo/router.md';
demoTest('breadcrumb', { skip: ['router.md'] });
const testMethod = typeof window !== 'undefined' ? test : test.skip;
testMethod('renders ./components/breadcrumb/demo/router.md correctly', () => {
const wrapper = render(routerDemo);
expect(renderToJson(wrapper)).toMatchSnapshot();
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('calendar');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('card');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('carousel');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('cascader');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('checkbox');

View File

@ -0,0 +1,23 @@
import React from 'react';
import { shallow } from 'enzyme';
import Checkbox from '..';
describe('Checkbox', () => {
it('responses hover events', () => {
const onMouseEnter = jest.fn();
const onMouseLeave = jest.fn();
const wrapper = shallow(
<Checkbox
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
/>
);
wrapper.simulate('mouseenter');
expect(onMouseEnter).toHaveBeenCalled();
wrapper.simulate('mouseleave');
expect(onMouseLeave).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('collapse');

Binary file not shown.

View File

@ -0,0 +1,14 @@
import { render } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import MockDate from 'mockdate';
import demoTest from '../../../tests/shared/demoTest';
demoTest('date-picker', { skip: ['locale.md'] });
test('renders ./components/date-picker/demo/locale.md correctly', () => {
MockDate.set(new Date('2016-11-22').getTime());
const LocaleDemo = require('../demo/locale'); // eslint-disable-line global-require
const wrapper = render(LocaleDemo);
expect(renderToJson(wrapper)).toMatchSnapshot();
MockDate.reset();
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('dropdown');

View File

@ -0,0 +1,36 @@
import React from 'react';
import { shallow } from 'enzyme';
import Dropdown from '..';
import Menu from '../../menu';
describe('DropdownButton', () => {
it('pass appropriate props to Dropdown', () => {
const props = {
align: {
offset: [10, 20],
},
overlay: (
<Menu>
<Menu.Item>foo</Menu.Item>
</Menu>
),
trigger: ['hover'],
visible: true,
onVisibleChange: () => {},
};
const wrapper = shallow(<Dropdown.Button {...props} />);
const dropdownProps = wrapper.find(Dropdown).props();
Object.keys(props).forEach((key) => {
expect(dropdownProps[key]).toBe(props[key]);
});
});
it('don\'t pass visible to Dropdown if it\'s not exits', () => {
const wrapper = shallow(<Dropdown.Button />);
const dropdownProps = wrapper.find(Dropdown).props();
expect('visible' in dropdownProps).toBe(false);
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('form');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('grid');

View File

@ -0,0 +1,20 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { Col, Row } from '..';
describe('Grid', () => {
it('should render Col', () => {
const col = TestUtils.renderIntoDocument(
<Col span="2" />
);
const colNode = TestUtils.findRenderedDOMComponentWithTag(col, 'DIV');
expect(colNode.className).toBe('ant-col-2');
});
it('should render Row', () => {
const row = TestUtils.renderIntoDocument(
<Row />
);
const rowNode = TestUtils.findRenderedDOMComponentWithTag(row, 'DIV');
expect(rowNode.className).toBe('ant-row');
});
});

View File

@ -0,0 +1,25 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { wrap } from 'react-stateless-wrapper';
import AntIcon from '..';
const Icon = wrap(AntIcon);
describe('Icon', () => {
let icon;
let iconNode;
beforeEach(() => {
icon = TestUtils.renderIntoDocument(
<Icon type="appstore" className="my-icon-classname" />
);
iconNode = TestUtils.findRenderedDOMComponentWithTag(icon, 'I');
});
it('should render to a <i class="xxx"></i>', () => {
expect(iconNode.tagName).toBe('I');
expect(iconNode.className).toContain('my-icon-classname');
expect(iconNode.className).toContain('anticon');
expect(iconNode.className).toContain('anticon-appstore');
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('input-number');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('input');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('locale-provider');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('mention', { skip: true });

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('menu');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('message');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('modal');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('notification');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('pagination');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('popconfirm');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('popover');

View File

@ -0,0 +1,25 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import Popover from '..';
describe('Popover', () => {
it('should show overlay when trigger is clicked', () => {
const popover = TestUtils.renderIntoDocument(
<Popover content="console.log('hello world')" title="code" trigger="click">
<span>show me your code</span>
</Popover>
);
expect(popover.getPopupDomNode()).toBe(null);
TestUtils.Simulate.click(
TestUtils.findRenderedDOMComponentWithTag(popover, 'span')
);
const popup = popover.getPopupDomNode();
expect(popup).not.toBe(null);
expect(popup.className).toContain('ant-popover-placement-top');
expect(popup.innerHTML).toMatch(/<div class="ant-popover-title".*?>code<\/div>/);
expect(popup.innerHTML).toMatch(/<div class="ant-popover-inner-content".*?>console\.log\('hello world'\)<\/div>/);
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('progress');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('radio');

View File

@ -0,0 +1,26 @@
import React from 'react';
import { shallow } from 'enzyme';
import Radio from '../radio';
import RadioGroup from '../group';
describe('Radio', () => {
it('responses hover events', () => {
const onMouseEnter = jest.fn();
const onMouseLeave = jest.fn();
const wrapper = shallow(
<RadioGroup
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
<Radio />
</RadioGroup>
);
wrapper.simulate('mouseenter');
expect(onMouseEnter).toHaveBeenCalled();
wrapper.simulate('mouseleave');
expect(onMouseLeave).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,23 @@
import React from 'react';
import { shallow } from 'enzyme';
import Radio from '../radio';
describe('Radio', () => {
it('responses hover events', () => {
const onMouseEnter = jest.fn();
const onMouseLeave = jest.fn();
const wrapper = shallow(
<Radio
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
/>
);
wrapper.simulate('mouseenter');
expect(onMouseEnter).toHaveBeenCalled();
wrapper.simulate('mouseleave');
expect(onMouseLeave).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('rate');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('select');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('slider');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('spin');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('steps');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('switch');

View File

@ -0,0 +1,87 @@
import React from 'react';
import { mount } from 'enzyme';
import createStore from '../createStore';
import SelectionBox from '../SelectionBox';
describe('SelectionBox', () => {
it('unchecked by selectedRowKeys ', () => {
const store = createStore({
selectedRowKeys: [],
selectionDirty: false,
});
const wrapper = mount(
<SelectionBox
store={store}
rowIndex="1"
disabled={false}
onChange={() => {}}
defaultSelection={[]}
/>
);
expect(wrapper.state()).toEqual({ checked: false });
});
it('checked by selectedRowKeys ', () => {
const store = createStore({
selectedRowKeys: ['1'],
selectionDirty: false,
});
const wrapper = mount(
<SelectionBox
store={store}
rowIndex="1"
disabled={false}
onChange={() => {}}
defaultSelection={[]}
/>
);
expect(wrapper.state()).toEqual({ checked: true });
});
it('checked by defaultSelection', () => {
const store = createStore({
selectedRowKeys: [],
selectionDirty: false,
});
const wrapper = mount(
<SelectionBox
store={store}
rowIndex="1"
disabled={false}
onChange={() => {}}
defaultSelection={['1']}
/>
);
expect(wrapper.state()).toEqual({ checked: true });
});
it('checked when store change', () => {
const store = createStore({
selectedRowKeys: [],
selectionDirty: false,
});
const wrapper = mount(
<SelectionBox
store={store}
rowIndex="1"
disabled={false}
onChange={() => {}}
defaultSelection={[]}
/>
);
store.setState({
selectedRowKeys: ['1'],
selectionDirty: true,
});
expect(wrapper.state()).toEqual({ checked: true });
});
});

View File

@ -0,0 +1,141 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Table from '../table';
describe('Table.filter', () => {
const filterFn = (value, record) => record.name === 'Lucy';
const column = {
title: 'Name',
dataIndex: 'name',
filters: [
{ text: 'Boy', value: 'boy' },
{ text: 'Girl', value: 'girl' },
{
text: 'Title',
value: 'title',
children: [
{ text: 'Designer', value: 'designer' },
{ text: 'Coder', value: 'coder' },
],
},
],
onFilter: filterFn,
};
const data = [
{ key: 0, name: 'Jack' },
{ key: 1, name: 'Lucy' },
{ key: 2, name: 'Tom' },
{ key: 3, name: 'Jerry' },
];
function createTable(props) {
return (
<Table
columns={[column]}
dataSource={data}
pagination={false}
{...props}
/>
);
}
it('renders filter correctly', () => {
const wrapper = render(createTable());
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('renders menu correctly', () => {
const wrapper = mount(createTable());
const dropdownWrapper = render(wrapper.find('Trigger').node.getComponent());
expect(renderToJson(dropdownWrapper)).toMatchSnapshot();
});
it('renders radio filter correctly', () => {
const wrapper = mount(createTable({
columns: [{
...column,
filterMultiple: false,
}],
}));
const dropdownWrapper = render(wrapper.find('Trigger').node.getComponent());
expect(renderToJson(dropdownWrapper)).toMatchSnapshot();
});
it('renders custom content correctly', () => {
const filter = (
<div className="custom-filter-dropdown">
custom filter
</div>
);
const wrapper = mount(createTable({
columns: [{
...column,
filterDropdown: filter,
}],
}));
const dropdownWrapper = render(wrapper.find('Trigger').node.getComponent());
expect(renderToJson(dropdownWrapper)).toMatchSnapshot();
});
it('can be controlled by filterDropdownVisible', () => {
const wrapper = mount(createTable({
columns: [{
...column,
filterDropdownVisible: true,
}],
}));
const dropdown = wrapper.find('Dropdown').first();
expect(dropdown.props().visible).toBe(true);
wrapper.setProps({ columns: [{
...column,
filterDropdownVisible: false,
}] });
expect(dropdown.props().visible).toBe(false);
});
it('fires change event when visible change', () => {
const handleChange = jest.fn();
const wrapper = mount(createTable({
columns: [{
...column,
onFilterDropdownVisibleChange: handleChange,
}],
}));
wrapper.find('Dropdown').first().simulate('click');
expect(handleChange).toBeCalledWith(true);
});
it('can be controlled by filteredValue', () => {
const wrapper = mount(createTable({
columns: [{
...column,
filteredValue: ['girl'],
}],
}));
expect(wrapper.find('tbody tr').length).toBe(1);
wrapper.setProps({ columns: [{
...column,
filteredValue: [],
}] });
expect(wrapper.find('tbody tr').length).toBe(4);
});
it('fires change event', () => {
const handleChange = jest.fn();
const wrapper = mount(createTable({ onChange: handleChange }));
const dropdownWrapper = mount(wrapper.find('Trigger').node.getComponent());
dropdownWrapper.find('MenuItem').first().simulate('click');
dropdownWrapper.find('.confirm').simulate('click');
expect(handleChange).toBeCalledWith({}, { name: ['boy'] }, {});
});
});

View File

@ -0,0 +1,78 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Table from '../table';
describe('Table.pagination', () => {
const columns = [{
title: 'Name',
dataIndex: 'name',
}];
const data = [
{ key: 0, name: 'Jack' },
{ key: 1, name: 'Lucy' },
{ key: 2, name: 'Tom' },
{ key: 3, name: 'Jerry' },
];
const pagination = { pageSize: 2 };
function createTable(props) {
return (
<Table
columns={columns}
dataSource={data}
pagination={pagination}
{...props}
/>
);
}
function renderedNames(wrapper) {
return wrapper.find('TableRow').map(row => row.props().record.name);
}
it('renders pagination correctly', () => {
const wrapper = render(createTable());
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('paginate data', () => {
const wrapper = mount(createTable());
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy']);
wrapper.find('Pager').last().simulate('click');
expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']);
});
it('repaginates when pageSize change', () => {
const wrapper = mount(createTable());
wrapper.setProps({ pagination: { pageSize: 1 } });
expect(renderedNames(wrapper)).toEqual(['Jack']);
});
it('fires change event', () => {
const handleChange = jest.fn();
const noop = () => {};
const wrapper = mount(createTable({
pagination: { ...pagination, onChange: noop, onShowSizeChange: noop },
onChange: handleChange,
}));
wrapper.find('Pager').last().simulate('click');
expect(handleChange).toBeCalledWith(
{
current: 2,
onChange: noop,
onShowSizeChange: noop,
pageSize: 2,
},
{},
{}
);
});
});

View File

@ -0,0 +1,166 @@
import React from 'react';
import { mount } from 'enzyme';
import Table from '../table';
describe('Table.rowSelection', () => {
const columns = [{
title: 'Name',
dataIndex: 'name',
}];
const data = [
{ key: 0, name: 'Jack' },
{ key: 1, name: 'Lucy' },
{ key: 2, name: 'Tom' },
{ key: 3, name: 'Jerry' },
];
function createTable(props = {}) {
return (
<Table
columns={columns}
dataSource={data}
rowSelection={{}}
{...props}
/>
);
}
it('select by checkbox', () => {
const wrapper = mount(createTable());
const checkboxes = wrapper.find('input');
const checkboxAll = checkboxes.first();
checkboxAll.simulate('change', { target: { checked: true } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [0, 1, 2, 3],
selectionDirty: true,
});
checkboxes.at(1).simulate('change', { target: { checked: false } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [1, 2, 3],
selectionDirty: true,
});
checkboxes.at(1).simulate('change', { target: { checked: true } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [1, 2, 3, 0],
selectionDirty: true,
});
});
it('select by radio', () => {
const wrapper = mount(createTable({ rowSelection: { type: 'radio' } }));
const radios = wrapper.find('input');
expect(radios.length).toBe(4);
radios.first().simulate('change', { target: { checked: true } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [0],
selectionDirty: true,
});
radios.last().simulate('change', { target: { checked: true } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [3],
selectionDirty: true,
});
});
it('pass getCheckboxProps to checkbox', () => {
const rowSelection = {
getCheckboxProps: record => ({
disabled: record.name === 'Lucy',
}),
};
const wrapper = mount(createTable({ rowSelection }));
const checkboxes = wrapper.find('input');
expect(checkboxes.at(1).props().disabled).toBe(false);
expect(checkboxes.at(2).props().disabled).toBe(true);
});
it('works with pagination', () => {
const wrapper = mount(createTable({ pagination: { pageSize: 2 } }));
const checkboxAll = wrapper.find('SelectionCheckboxAll');
const pagers = wrapper.find('Pager');
checkboxAll.find('input').simulate('change', { target: { checked: true } });
expect(checkboxAll.node.state).toEqual({ checked: true, indeterminate: false });
pagers.at(1).simulate('click');
expect(checkboxAll.node.state).toEqual({ checked: false, indeterminate: false });
pagers.at(0).simulate('click');
expect(checkboxAll.node.state).toEqual({ checked: true, indeterminate: false });
});
// https://github.com/ant-design/ant-design/issues/4020
it('handles defaultChecked', () => {
const rowSelection = {
getCheckboxProps: record => ({
defaultChecked: record.key === 0,
}),
};
const wrapper = mount(createTable({ rowSelection }));
const checkboxs = wrapper.find('input');
expect(checkboxs.at(1).props().checked).toBe(true);
expect(checkboxs.at(2).props().checked).toBe(false);
checkboxs.at(2).simulate('change', { target: { checked: true } });
expect(checkboxs.at(1).props().checked).toBe(true);
expect(checkboxs.at(2).props().checked).toBe(true);
});
it('can be controlled', () => {
const wrapper = mount(createTable({ rowSelection: { selectedRowKeys: [0] } }));
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [0],
selectionDirty: false,
});
wrapper.setProps({ rowSelection: { selectedRowKeys: [1] } });
expect(wrapper.instance().store.getState()).toEqual({
selectedRowKeys: [1],
selectionDirty: false,
});
});
it('fires change & select events', () => {
const handleChange = jest.fn();
const handleSelect = jest.fn();
const rowSelection = {
onChange: handleChange,
onSelect: handleSelect,
};
const wrapper = mount(createTable({ rowSelection }));
wrapper.find('input').last().simulate('change', { target: { checked: true } });
expect(handleChange).toBeCalledWith([3], [{ key: 3, name: 'Jerry' }]);
expect(handleSelect).toBeCalledWith(
{ key: 3, name: 'Jerry' },
true,
[{ key: 3, name: 'Jerry' }]
);
});
it('fires selectAll event', () => {
const handleSelectAll = jest.fn();
const rowSelection = {
onSelectAll: handleSelectAll,
};
const wrapper = mount(createTable({ rowSelection }));
wrapper.find('input').first().simulate('change', { target: { checked: true } });
expect(handleSelectAll).toBeCalledWith(true, data, data);
});
});

View File

@ -0,0 +1,71 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Table from '../table';
describe('Table.sorter', () => {
const sorterFn = (a, b) => a.name[0].charCodeAt() - b.name[0].charCodeAt();
const column = {
title: 'Name',
dataIndex: 'name',
sorter: sorterFn,
};
const data = [
{ key: 0, name: 'Jack' },
{ key: 1, name: 'Lucy' },
{ key: 2, name: 'Tom' },
{ key: 3, name: 'Jerry' },
];
function createTable(props) {
return (
<Table
columns={[column]}
dataSource={data}
pagination={false}
{...props}
/>
);
}
function renderedNames(wrapper) {
return wrapper.find('TableRow').map(row => row.props().record.name);
}
it('renders sorter icon correctly', () => {
const wrapper = render(createTable());
expect(renderToJson(wrapper.find('thead'))).toMatchSnapshot();
});
it('sort records', () => {
const wrapper = mount(createTable());
wrapper.find('.ant-table-column-sorter-up').simulate('click');
expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']);
wrapper.find('.ant-table-column-sorter-down').simulate('click');
expect(renderedNames(wrapper)).toEqual(['Tom', 'Lucy', 'Jack', 'Jerry']);
});
it('can be controlled by sortOrder', () => {
const wrapper = mount(createTable({
columns: [{ ...column, sortOrder: 'ascend' }],
}));
expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']);
});
it('fires change event', () => {
const handleChange = jest.fn();
const wrapper = mount(createTable({ onChange: handleChange }));
wrapper.find('.ant-table-column-sorter-up').simulate('click');
const sorter = handleChange.mock.calls[0][2];
expect(sorter.column.dataIndex).toBe('name');
expect(sorter.order).toBe('ascend');
expect(sorter.field).toBe('name');
expect(sorter.columnKey).toBe('name');
});
});

View File

@ -0,0 +1,63 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Table from '../table';
const { Column, ColumnGroup } = Table;
describe('Table', () => {
it('renders JSX correctly', () => {
const data = [{
key: '1',
firstName: 'John',
lastName: 'Brown',
age: 32,
}, {
key: '2',
firstName: 'Jim',
lastName: 'Green',
age: 42,
}];
const wrapper = render(
<Table dataSource={data} pagination={false}>
<ColumnGroup title="Name">
<Column
title="First Name"
dataIndex="firstName"
key="firstName"
/>
<Column
title="Last Name"
dataIndex="lastName"
key="lastName"
/>
</ColumnGroup>
<Column
title="Age"
dataIndex="age"
key="age"
/>
</Table>
);
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('updates columns when receiving props', () => {
const columns = [{
title: 'Name',
key: 'name',
dataIndex: 'name',
}];
const wrapper = shallow(<Table columns={columns} />);
const newColumns = [{
title: 'Title',
key: 'title',
dataIndex: 'title',
}];
wrapper.setProps({ columns: newColumns });
expect(wrapper.instance().columns).toBe(newColumns);
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('table');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('tabs');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('tag');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('time-picker');

View File

@ -0,0 +1,16 @@
import React from 'react';
import { mount, render } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import RcTimePicker from 'rc-time-picker/lib/TimePicker';
import TimePicker from '..';
describe('TimePicker', () => {
it('renders addon correctly', () => {
const addon = () => (<button>Ok</button>);
const wrapper = mount(<TimePicker addon={addon} />);
const rcTimePicker = wrapper.find(RcTimePicker);
const addonWrapper = render(rcTimePicker.props().addon());
expect(renderToJson(addonWrapper)).toMatchSnapshot();
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('timeline');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('tooltip');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('transfer');

View File

@ -0,0 +1,16 @@
import React from 'react';
import { mount } from 'enzyme';
import { mountToJson } from 'enzyme-to-json';
import Search from '../search';
describe('Search', () => {
it('should show cross icon when input value exists', () => {
const wrapper = mount(<Search value={''} />);
expect(mountToJson(wrapper)).toMatchSnapshot();
wrapper.setProps({ value: 'a' });
expect(mountToJson(wrapper)).toMatchSnapshot();
});
});

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('tree-select');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('tree');

View File

@ -0,0 +1,3 @@
import demoTest from '../../../tests/shared/demoTest';
demoTest('upload');