diff --git a/components/drawer/__tests__/Drawer.test.js b/components/drawer/__tests__/Drawer.test.js index 063ecf6668..379f443160 100644 --- a/components/drawer/__tests__/Drawer.test.js +++ b/components/drawer/__tests__/Drawer.test.js @@ -54,4 +54,18 @@ describe('Drawer', () => { ); expect(wrapper).toMatchSnapshot(); }); + + it('wrapClassName is test_drawer', () => { + const wrapper = render( + + Here is content of Drawer + + ); + expect(wrapper).toMatchSnapshot(); + }); }); diff --git a/components/drawer/__tests__/MultiDrawer.test.js b/components/drawer/__tests__/MultiDrawer.test.js new file mode 100644 index 0000000000..f1abfccc15 --- /dev/null +++ b/components/drawer/__tests__/MultiDrawer.test.js @@ -0,0 +1,116 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Drawer from '..'; +import Button from '../../button'; + +class MultiDrawer extends React.Component { + state = { visible: false, childrenDrawer: false }; + + showDrawer = () => { + this.setState({ + visible: true, + }); + }; + + onClose = () => { + this.setState({ + visible: false, + }); + }; + + showChildrenDrawer = () => { + this.setState({ + childrenDrawer: true, + }); + }; + + onChildrenDrawerClose = () => { + this.setState({ + childrenDrawer: false, + }); + }; + + render() { + const { childrenDrawer, visible } = this.state; + const { placement } = this.props; + return ( +
+ + + + +
+ This is two-level drawer +
+
+
+ + +
+
+
+ ); + } +} + +describe('Drawer', () => { + it('render right MultiDrawer', () => { + const wrapper = mount(); + wrapper.find('button#open_drawer').simulate('click'); + wrapper.find('button#open_two_drawer').simulate('click'); + const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + expect(translateX).toEqual('translateX(-180px)'); + expect(wrapper.find('#two_drawer_text').exists()).toBe(true); + }); + + it('render right MultiDrawer', () => { + const wrapper = mount(); + wrapper.find('button#open_drawer').simulate('click'); + wrapper.find('button#open_two_drawer').simulate('click'); + const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + expect(translateX).toEqual('translateX(180px)'); + expect(wrapper.find('#two_drawer_text').exists()).toBe(true); + }); +}); diff --git a/components/drawer/__tests__/__snapshots__/Drawer.test.js.snap b/components/drawer/__tests__/__snapshots__/Drawer.test.js.snap index f8a25d41c7..3c4721abfb 100644 --- a/components/drawer/__tests__/__snapshots__/Drawer.test.js.snap +++ b/components/drawer/__tests__/__snapshots__/Drawer.test.js.snap @@ -164,3 +164,44 @@ exports[`Drawer render correctly 1`] = ` `; + +exports[`Drawer wrapClassName is test_drawer 1`] = ` +
+
+
+
+
+
+ +
+ Here is content of Drawer +
+
+
+
+
+
+`; diff --git a/components/drawer/demo/multi-level-drawer.md b/components/drawer/demo/multi-level-drawer.md index 89a0754646..5146537786 100644 --- a/components/drawer/demo/multi-level-drawer.md +++ b/components/drawer/demo/multi-level-drawer.md @@ -52,6 +52,7 @@ class App extends React.Component { { } this.destoryClose = false; const { placement } = this.props; + const containerStyle: React.CSSProperties = placement === 'left' || placement === 'right' ? { overflow: 'auto', height: '100%', } : {}; + const isDestroyOnClose = this.getDestoryOnClose(); if (isDestroyOnClose) { // Increase the opacity transition, delete children after closing. @@ -191,7 +193,7 @@ export default class Drawer extends React.Component { showMask={this.props.mask} placement={placement} style={RcDrawerStyle} - class={this.props.wrapClassName} + className={this.props.wrapClassName} > {this.renderBody()}