2018-07-22 11:27:48 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Drawer from '..';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2018-07-22 11:27:48 +08:00
|
|
|
import Button from '../../button';
|
|
|
|
|
|
|
|
class MultiDrawer extends React.Component {
|
2019-07-17 20:41:53 +08:00
|
|
|
state = { visible: false, childrenDrawer: false, hasChildren: true };
|
2018-07-22 11:27:48 +08:00
|
|
|
|
|
|
|
showDrawer = () => {
|
|
|
|
this.setState({
|
|
|
|
visible: true,
|
2019-07-17 20:41:53 +08:00
|
|
|
hasChildren: true,
|
2018-07-22 11:27:48 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
this.setState({
|
|
|
|
visible: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
showChildrenDrawer = () => {
|
|
|
|
this.setState({
|
|
|
|
childrenDrawer: true,
|
2019-07-17 20:41:53 +08:00
|
|
|
hasChildren: true,
|
2018-07-22 11:27:48 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onChildrenDrawerClose = () => {
|
|
|
|
this.setState({
|
|
|
|
childrenDrawer: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-07-17 20:41:53 +08:00
|
|
|
onRemoveChildDrawer = () => {
|
|
|
|
this.setState({
|
|
|
|
hasChildren: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-07-22 11:27:48 +08:00
|
|
|
render() {
|
2019-07-17 20:41:53 +08:00
|
|
|
const { childrenDrawer, visible, hasChildren } = this.state;
|
2020-07-12 18:47:14 +08:00
|
|
|
const { placement, push } = this.props;
|
2018-07-22 11:27:48 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button type="primary" id="open_drawer" onClick={this.showDrawer}>
|
|
|
|
Open drawer
|
|
|
|
</Button>
|
2019-07-17 20:41:53 +08:00
|
|
|
<Button type="primary" id="remove_drawer" onClick={this.onRemoveChildDrawer}>
|
|
|
|
rm child drawer
|
|
|
|
</Button>
|
2018-07-22 11:27:48 +08:00
|
|
|
<Drawer
|
|
|
|
title="Multi-level drawer"
|
2018-08-05 14:28:39 +08:00
|
|
|
className="test_drawer"
|
2018-07-22 11:27:48 +08:00
|
|
|
width={520}
|
|
|
|
onClose={this.onClose}
|
|
|
|
getContainer={false}
|
|
|
|
placement={placement}
|
|
|
|
visible={visible}
|
2020-07-12 18:47:14 +08:00
|
|
|
push={push}
|
2018-07-22 11:27:48 +08:00
|
|
|
>
|
|
|
|
<Button type="primary" id="open_two_drawer" onClick={this.showChildrenDrawer}>
|
2018-12-07 16:17:45 +08:00
|
|
|
Two-level drawer
|
2018-07-22 11:27:48 +08:00
|
|
|
</Button>
|
2019-07-17 20:41:53 +08:00
|
|
|
{hasChildren && (
|
|
|
|
<Drawer
|
|
|
|
title="Two-level Drawer"
|
|
|
|
width={320}
|
|
|
|
className="Two-level"
|
|
|
|
getContainer={false}
|
|
|
|
placement={placement}
|
|
|
|
onClose={this.onChildrenDrawerClose}
|
|
|
|
visible={childrenDrawer}
|
|
|
|
>
|
|
|
|
<div id="two_drawer_text">This is two-level drawer</div>
|
|
|
|
</Drawer>
|
|
|
|
)}
|
2018-07-22 11:27:48 +08:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: 0,
|
|
|
|
width: '100%',
|
|
|
|
borderTop: '1px solid #e8e8e8',
|
|
|
|
padding: '10px 16px',
|
|
|
|
textAlign: 'right',
|
|
|
|
left: 0,
|
|
|
|
background: '#fff',
|
|
|
|
borderRadius: '0 0 4px 4px',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
style={{
|
|
|
|
marginRight: 8,
|
|
|
|
}}
|
|
|
|
onClick={this.onClose}
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.onClose} type="primary">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Drawer>
|
2022-04-18 21:02:11 +08:00
|
|
|
|
|
|
|
<div className="childrenDrawer">{String(childrenDrawer)}</div>
|
2018-07-22 11:27:48 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Drawer', () => {
|
|
|
|
it('render right MultiDrawer', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer placement="right" />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2018-07-22 11:27:48 +08:00
|
|
|
expect(translateX).toEqual('translateX(-180px)');
|
2022-06-01 09:40:25 +08:00
|
|
|
expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1);
|
2018-07-22 11:27:48 +08:00
|
|
|
});
|
|
|
|
|
2018-08-10 13:32:33 +08:00
|
|
|
it('render left MultiDrawer', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer placement="left" />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2018-07-22 11:27:48 +08:00
|
|
|
expect(translateX).toEqual('translateX(180px)');
|
2022-06-01 09:40:25 +08:00
|
|
|
expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1);
|
|
|
|
fireEvent.click(wrapper.querySelector('.Two-level .ant-drawer-close'));
|
|
|
|
expect(wrapper.querySelector('.childrenDrawer').innerHTML).toEqual('false');
|
2018-08-19 14:51:28 +08:00
|
|
|
});
|
|
|
|
|
2019-04-03 15:54:26 +08:00
|
|
|
it('render top MultiDrawer', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer placement="top" />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2018-08-19 14:51:28 +08:00
|
|
|
expect(translateX).toEqual('translateY(180px)');
|
2022-06-01 09:40:25 +08:00
|
|
|
expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1);
|
2018-07-22 11:27:48 +08:00
|
|
|
});
|
2019-07-17 20:41:53 +08:00
|
|
|
|
|
|
|
it('render MultiDrawer is child in unmount', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer placement="top" mask={false} />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#remove_drawer'));
|
|
|
|
let translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
|
|
|
expect(translateX).toEqual('');
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2019-07-17 20:41:53 +08:00
|
|
|
expect(translateX).toEqual('translateY(180px)');
|
2022-06-01 09:40:25 +08:00
|
|
|
expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1);
|
2019-07-17 20:41:53 +08:00
|
|
|
});
|
2020-07-12 18:47:14 +08:00
|
|
|
|
|
|
|
it('custom MultiDrawer push distance', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer push={{ distance: 256 }} />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2020-07-12 18:47:14 +08:00
|
|
|
expect(translateX).toEqual('translateX(-256px)');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('custom MultiDrawer push with true', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer push />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
2020-07-12 18:47:14 +08:00
|
|
|
expect(translateX).toEqual('translateX(-180px)');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('custom MultiDrawer push with false', () => {
|
2022-06-01 09:40:25 +08:00
|
|
|
const { container: wrapper } = render(<MultiDrawer push={false} />);
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_drawer'));
|
|
|
|
fireEvent.click(wrapper.querySelector('button#open_two_drawer'));
|
|
|
|
const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform;
|
|
|
|
expect(translateX).toEqual('');
|
2020-07-12 18:47:14 +08:00
|
|
|
});
|
2018-07-22 11:27:48 +08:00
|
|
|
});
|