mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-29 18:50:00 +08:00
Don't ignore test files.
This commit is contained in:
parent
17a0a33283
commit
07103b9fb6
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,3 +31,4 @@ components/**/*.js
|
||||
components/**/*.jsx
|
||||
/.vscode/
|
||||
/coverage
|
||||
!components/**/__tests__/*
|
||||
|
3
components/affix/__tests__/demo.test.js
Normal file
3
components/affix/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('affix');
|
3
components/alert/__tests__/demo.test.js
Normal file
3
components/alert/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('alert');
|
20
components/anchor/__tests__/Anchor.test.js
Normal file
20
components/anchor/__tests__/Anchor.test.js
Normal 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);
|
||||
});
|
||||
});
|
3
components/anchor/__tests__/demo.test.js
Normal file
3
components/anchor/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('anchor');
|
3
components/auto-complete/__tests__/demo.test.js
Normal file
3
components/auto-complete/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('auto-complete');
|
3
components/back-top/__tests__/demo.test.js
Normal file
3
components/back-top/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('back-top');
|
3
components/badge/__tests__/demo.test.js
Normal file
3
components/badge/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('badge');
|
12
components/breadcrumb/__tests__/demo.test.js
Normal file
12
components/breadcrumb/__tests__/demo.test.js
Normal 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();
|
||||
});
|
3
components/calendar/__tests__/demo.test.js
Normal file
3
components/calendar/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('calendar');
|
3
components/card/__tests__/demo.test.js
Normal file
3
components/card/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('card');
|
3
components/carousel/__tests__/demo.test.js
Normal file
3
components/carousel/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('carousel');
|
3
components/cascader/__tests__/demo.test.js
Normal file
3
components/cascader/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('cascader');
|
3
components/checkbox/__tests__/demo.test.js
Normal file
3
components/checkbox/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('checkbox');
|
23
components/checkbox/__tests__/index.test.js
Normal file
23
components/checkbox/__tests__/index.test.js
Normal 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();
|
||||
});
|
||||
});
|
3
components/collapse/__tests__/demo.test.js
Normal file
3
components/collapse/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('collapse');
|
BIN
components/date-picker/__tests__/.demo.test.js.swp
Normal file
BIN
components/date-picker/__tests__/.demo.test.js.swp
Normal file
Binary file not shown.
14
components/date-picker/__tests__/demo.test.js
Normal file
14
components/date-picker/__tests__/demo.test.js
Normal 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();
|
||||
});
|
3
components/dropdown/__tests__/demo.test.js
Normal file
3
components/dropdown/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('dropdown');
|
36
components/dropdown/__tests__/dropdown-button.test.js
Normal file
36
components/dropdown/__tests__/dropdown-button.test.js
Normal 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);
|
||||
});
|
||||
});
|
3
components/form/__tests__/demo.test.js
Normal file
3
components/form/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('form');
|
3
components/grid/__tests__/demo.test.js
Normal file
3
components/grid/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('grid');
|
20
components/grid/__tests__/index.test.js
Normal file
20
components/grid/__tests__/index.test.js
Normal 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');
|
||||
});
|
||||
});
|
25
components/icon/__tests__/index.test.js
Normal file
25
components/icon/__tests__/index.test.js
Normal 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');
|
||||
});
|
||||
});
|
3
components/input-number/__tests__/demo.test.js
Normal file
3
components/input-number/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('input-number');
|
3
components/input/__tests__/demo.test.js
Normal file
3
components/input/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('input');
|
3
components/locale-provider/__tests__/demo.test.js
Normal file
3
components/locale-provider/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('locale-provider');
|
3
components/mention/__tests__/demo.test.js
Normal file
3
components/mention/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('mention', { skip: true });
|
3
components/menu/__tests__/demo.test.js
Normal file
3
components/menu/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('menu');
|
3
components/message/__tests__/demo.test.js
Normal file
3
components/message/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('message');
|
3
components/modal/__tests__/demo.test.js
Normal file
3
components/modal/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('modal');
|
3
components/notification/__tests__/demo.test.js
Normal file
3
components/notification/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('notification');
|
3
components/pagination/__tests__/demo.test.js
Normal file
3
components/pagination/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('pagination');
|
3
components/popconfirm/__tests__/demo.test.js
Normal file
3
components/popconfirm/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('popconfirm');
|
3
components/popover/__tests__/demo.test.js
Normal file
3
components/popover/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('popover');
|
25
components/popover/__tests__/index.test.js
Normal file
25
components/popover/__tests__/index.test.js
Normal 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>/);
|
||||
});
|
||||
});
|
3
components/progress/__tests__/demo.test.js
Normal file
3
components/progress/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('progress');
|
3
components/radio/__tests__/demo.test.js
Normal file
3
components/radio/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('radio');
|
26
components/radio/__tests__/group.test.js
Normal file
26
components/radio/__tests__/group.test.js
Normal 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();
|
||||
});
|
||||
});
|
23
components/radio/__tests__/radio.test.js
Normal file
23
components/radio/__tests__/radio.test.js
Normal 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();
|
||||
});
|
||||
});
|
3
components/rate/__tests__/demo.test.js
Normal file
3
components/rate/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('rate');
|
3
components/select/__tests__/demo.test.js
Normal file
3
components/select/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('select');
|
3
components/slider/__tests__/demo.test.js
Normal file
3
components/slider/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('slider');
|
3
components/spin/__tests__/demo.test.js
Normal file
3
components/spin/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('spin');
|
3
components/steps/__tests__/demo.test.js
Normal file
3
components/steps/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('steps');
|
3
components/switch/__tests__/demo.test.js
Normal file
3
components/switch/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('switch');
|
87
components/table/__tests__/SelectionBox.test.js
Normal file
87
components/table/__tests__/SelectionBox.test.js
Normal 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 });
|
||||
});
|
||||
});
|
141
components/table/__tests__/Table.filter.test.js
Normal file
141
components/table/__tests__/Table.filter.test.js
Normal 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'] }, {});
|
||||
});
|
||||
});
|
78
components/table/__tests__/Table.pagination.test.js
Normal file
78
components/table/__tests__/Table.pagination.test.js
Normal 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,
|
||||
},
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
});
|
166
components/table/__tests__/Table.rowSelection.test.js
Normal file
166
components/table/__tests__/Table.rowSelection.test.js
Normal 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);
|
||||
});
|
||||
});
|
71
components/table/__tests__/Table.sorter.test.js
Normal file
71
components/table/__tests__/Table.sorter.test.js
Normal 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');
|
||||
});
|
||||
});
|
63
components/table/__tests__/Table.test.js
Normal file
63
components/table/__tests__/Table.test.js
Normal 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);
|
||||
});
|
||||
});
|
3
components/table/__tests__/demo.test.js
Normal file
3
components/table/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('table');
|
3
components/tabs/__tests__/demo.test.js
Normal file
3
components/tabs/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tabs');
|
3
components/tag/__tests__/demo.test.js
Normal file
3
components/tag/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tag');
|
3
components/time-picker/__tests__/demo.test.js
Normal file
3
components/time-picker/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('time-picker');
|
16
components/time-picker/__tests__/index.test.js
Normal file
16
components/time-picker/__tests__/index.test.js
Normal 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();
|
||||
});
|
||||
});
|
3
components/timeline/__tests__/demo.test.js
Normal file
3
components/timeline/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('timeline');
|
3
components/tooltip/__tests__/demo.test.js
Normal file
3
components/tooltip/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tooltip');
|
3
components/transfer/__tests__/demo.test.js
Normal file
3
components/transfer/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('transfer');
|
16
components/transfer/__tests__/search.test.js
Normal file
16
components/transfer/__tests__/search.test.js
Normal 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();
|
||||
});
|
||||
});
|
3
components/tree-select/__tests__/demo.test.js
Normal file
3
components/tree-select/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tree-select');
|
3
components/tree/__tests__/demo.test.js
Normal file
3
components/tree/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tree');
|
3
components/upload/__tests__/demo.test.js
Normal file
3
components/upload/__tests__/demo.test.js
Normal file
@ -0,0 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('upload');
|
Loading…
Reference in New Issue
Block a user