test support react15

This commit is contained in:
陈帅 2018-06-26 11:19:49 +08:00
parent 2e3d131d74
commit 0f22cd69c3
6 changed files with 150 additions and 144 deletions

View File

@ -2,50 +2,56 @@ import React from 'react';
import { mount } from 'enzyme';
import Drawer from '..';
class DrawerTester extends React.Component {
saveContainer = (container) => {
this.container = container;
}
getContainer = () => {
return this.container;
}
render() {
return (
<div>
<div ref={this.saveContainer} />
describe('Drawer', () => {
it('render correctly', () => {
const wrapper = mount(
<Drawer
visible
getContainer={this.getContainer}
{...this.props}
width={400}
getContainer={false}
>
Here is content of Drawer
</Drawer>
</div>
);
}
}
describe('Drawer', () => {
it('render correctly', () => {
const wrapper = mount(<DrawerTester width={400} />);
expect(wrapper.render()).toMatchSnapshot();
});
it('have a title', () => {
const wrapper = mount(<DrawerTester title="Test Title" />);
const wrapper = mount(
<Drawer
visible
title="Test Title"
getContainer={false}
>
Here is content of Drawer
</Drawer>
);
expect(wrapper.render()).toMatchSnapshot();
});
it('closable is false', () => {
const wrapper = mount(<DrawerTester closable={false} />);
const wrapper = mount(
<Drawer
visible
closable={false}
getContainer={false}
>
Here is content of Drawer
</Drawer>
);
expect(wrapper.render()).toMatchSnapshot();
});
it('destroyOnClose is true', () => {
const wrapper = mount(<DrawerTester destroyOnClose visible={false} />);
const wrapper = mount(
<Drawer
destroyOnClose
visible={false}
getContainer={false}
>
Here is content of Drawer
</Drawer>
);
expect(wrapper.render()).toMatchSnapshot();
});
});

View File

@ -13,14 +13,6 @@ class DrawerEventTester extends React.Component {
this.setState({ visible: true }); // eslint-disable-line react/no-did-mount-set-state
}
saveContainer = (container) => {
this.container = container;
};
getContainer = () => {
return this.container;
};
onClose = () => {
this.setState({
visible: false,
@ -38,12 +30,11 @@ class DrawerEventTester extends React.Component {
return (
<div>
<Button onClick={this.open}>open</Button>
<div ref={this.saveContainer} />
<Drawer
visible={visible}
onClose={this.onClose}
destroyOnClose
getContainer={this.getContainer}
getContainer={false}
{...this.props}
>
Here is content of Drawer

View File

@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Drawer closable is false 1`] = `
<div>
<div>
<div>
<div
class=""
>
<div
class="ant-drawer ant-drawer-left ant-drawer-open"
>
@ -29,20 +29,33 @@ exports[`Drawer closable is false 1`] = `
</div>
</div>
</div>
</div>
</div>
`;
exports[`Drawer destroyOnClose is true 1`] = `
<div>
<div />
<div
class=""
>
<div
class="ant-drawer ant-drawer-left"
>
<div
class="ant-drawer-mask"
/>
<div
class="ant-drawer-content-wrapper"
>
<div
class="ant-drawer-content"
/>
</div>
</div>
</div>
`;
exports[`Drawer have a title 1`] = `
<div>
<div>
<div>
<div
class=""
>
<div
class="ant-drawer ant-drawer-left ant-drawer-open"
>
@ -85,14 +98,12 @@ exports[`Drawer have a title 1`] = `
</div>
</div>
</div>
</div>
</div>
`;
exports[`Drawer render correctly 1`] = `
<div>
<div>
<div>
<div
class=""
>
<div
class="ant-drawer ant-drawer-left ant-drawer-open"
>
@ -126,6 +137,4 @@ exports[`Drawer render correctly 1`] = `
</div>
</div>
</div>
</div>
</div>
`;

View File

@ -10,8 +10,9 @@ exports[`Drawer render correctly 1`] = `
open
</span>
</button>
<div>
<div>
<div
class=""
>
<div
class="ant-drawer ant-drawer-left ant-drawer-open"
>
@ -46,5 +47,4 @@ exports[`Drawer render correctly 1`] = `
</div>
</div>
</div>
</div>
`;

View File

@ -37,7 +37,7 @@ export default class Drawer extends React.Component<
static propTypes = {
closable: PropTypes.bool,
destroyOnClose: PropTypes.bool,
getContainer: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.func]),
getContainer: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.func, PropTypes.bool]),
maskClosable: PropTypes.bool,
mask: PropTypes.bool,
maskStyle: PropTypes.object,

View File

@ -58,7 +58,7 @@
"rc-checkbox": "~2.1.5",
"rc-collapse": "~1.9.0",
"rc-dialog": "~7.1.0",
"rc-drawer": "~1.4.1",
"rc-drawer": "~1.4.2",
"rc-dropdown": "~2.2.0",
"rc-editor-mention": "^1.0.2",
"rc-form": "^2.1.0",