Skip to content

Commit c9bcbd4

Browse files
committed
add test
1 parent 1104625 commit c9bcbd4

File tree

1 file changed

+71
-12
lines changed

1 file changed

+71
-12
lines changed

tests/index.spec.tsx

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { mount } from 'enzyme';
22
import * as React from 'react';
33
import toJson from 'enzyme-to-json';
4-
import Drawer from '../src/';
4+
import Drawer from "../src";
55

66
function Div(props) {
7-
const { show, ...otherProps } = props
7+
const { show, ...otherProps } = props;
88
return (
99
<div className="div-wrapper">
10-
{show && <Drawer wrapperClassName="drawer-wrapper" defaultOpen {...otherProps} />}
10+
{show && (
11+
<Drawer wrapperClassName="drawer-wrapper" defaultOpen {...otherProps} />
12+
)}
1113
</div>
1214
);
1315
}
@@ -18,7 +20,26 @@ function DrawerComp(props: { open?: boolean }) {
1820
<div id="a" style={{ position: 'absolute', top: 0, left: 0 }}>
1921
test1
2022
</div>
21-
<Drawer getContainer={null} open={props.open} wrapperClassName="drawer-wrapper" />
23+
<Drawer
24+
getContainer={null}
25+
open={props.open}
26+
wrapperClassName="drawer-wrapper"
27+
/>
28+
</div>
29+
);
30+
}
31+
32+
function TowDrawer(props: { oneOpen?: boolean; towOpen?: boolean }) {
33+
return (
34+
<div className="tow-wrapper">
35+
<div
36+
id="a"
37+
className="a"
38+
style={{ position: 'absolute', top: 0, left: 0 }}
39+
>
40+
<Drawer getContainer="#a" open={props.oneOpen} />
41+
</div>
42+
<Drawer open={props.towOpen} />
2243
</div>
2344
);
2445
}
@@ -32,7 +53,10 @@ function createStartTouchEventObject({ x = 0, y = 0 }) {
3253
}
3354

3455
function createMoveTouchEventObject({ x = 0, y = 0 }) {
35-
return { touches: [createClientXY(x, y)], changedTouches: [createClientXY(x, y)] };
56+
return {
57+
touches: [createClientXY(x, y)],
58+
changedTouches: [createClientXY(x, y)],
59+
};
3660
}
3761

3862
describe('rc-drawer-menu', () => {
@@ -64,11 +88,19 @@ describe('rc-drawer-menu', () => {
6488
});
6589

6690
it('default open drawer', () => {
67-
instance = mount(<Drawer handler={<i className="a">a</i>} defaultOpen={true} level={[]} />);
91+
instance = mount(
92+
<Drawer handler={<i className="a">a</i>} defaultOpen level={[]} />,
93+
);
6894
const drawer = instance.find('.drawer-content-wrapper').instance() as any;
6995
const content = instance.find('.drawer-content');
70-
content.simulate('touchStart', createStartTouchEventObject({ x: 100, y: 0 }));
71-
content.simulate('touchMove', createMoveTouchEventObject({ x: 150, y: 10 }));
96+
content.simulate(
97+
'touchStart',
98+
createStartTouchEventObject({ x: 100, y: 0 }),
99+
);
100+
content.simulate(
101+
'touchMove',
102+
createMoveTouchEventObject({ x: 150, y: 10 }),
103+
);
72104
content.simulate('touchEnd', createMoveTouchEventObject({ x: 200, y: 0 }));
73105
content.simulate('touchStart', createStartTouchEventObject({ x: 0, y: 0 }));
74106
content.simulate('touchMove', createMoveTouchEventObject({ x: 0, y: 10 }));
@@ -78,7 +110,7 @@ describe('rc-drawer-menu', () => {
78110
});
79111

80112
it('handler is null,open=true', () => {
81-
instance = mount(<Drawer handler={null} open={true} level={null} />);
113+
instance = mount(<Drawer handler={null} open level={null} />);
82114
expect(toJson(instance.render())).toMatchSnapshot();
83115
});
84116
it('handler is null,open=false', () => {
@@ -111,12 +143,16 @@ describe('rc-drawer-menu', () => {
111143
it('getContainer is null', () => {
112144
instance = mount(
113145
<div className="react-wrapper">
114-
<div id="a" className="a" style={{ position: 'absolute', top: 0, left: 0 }}>
146+
<div
147+
id="a"
148+
className="a"
149+
style={{ position: 'absolute', top: 0, left: 0 }}
150+
>
115151
test1
116152
</div>
117153
<Drawer
118154
getContainer={null}
119-
defaultOpen={true}
155+
defaultOpen
120156
level="#a"
121157
wrapperClassName="drawer-wrapper"
122158
/>
@@ -146,7 +182,7 @@ describe('rc-drawer-menu', () => {
146182
expect(content.style.transform).toBe('translateX(-100%)');
147183
});
148184
it('will unmount', () => {
149-
instance = mount(<Div show={true} />);
185+
instance = mount(<Div show />);
150186
const divWrapper = instance.find('.div-wrapper').instance() as any;
151187
const content = instance.find('.drawer-content-wrapper').instance() as any;
152188
console.log(content.style.transform);
@@ -196,4 +232,27 @@ describe('rc-drawer-menu', () => {
196232
});
197233
expect(toJson(instance.render())).toMatchSnapshot();
198234
});
235+
it.only('tow drawer getContainer', () => {
236+
instance = mount(<TowDrawer />);
237+
jest.useFakeTimers();
238+
instance.setProps({
239+
oneOpen: true,
240+
});
241+
jest.runAllTimers();
242+
expect(document.body.style.cssText).toEqual('');
243+
console.log(document.body.style.cssText);
244+
instance.setProps({
245+
towOpen: true,
246+
});
247+
jest.runAllTimers();
248+
console.log(document.body.style.cssText);
249+
expect(document.body.style.cssText).toBe('overflow: hidden;');
250+
instance.setProps({
251+
towOpen: false,
252+
});
253+
jest.runAllTimers();
254+
console.log(document.body.style.cssText);
255+
expect(document.body.style.cssText).toEqual('');
256+
jest.useRealTimers();
257+
});
199258
});

0 commit comments

Comments
 (0)