Skip to content

Commit 92d0e3d

Browse files
committed
feat: add slidePane test case
1 parent d736d1b commit 92d0e3d

File tree

7 files changed

+16411
-23
lines changed

7 files changed

+16411
-23
lines changed

package-lock.json

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@types/classnames": "^2.2.10",
7575
"@types/enzyme": "^3.10.5",
7676
"@types/history": "^4.7.0",
77-
"@types/jest": "^25.2.3",
77+
"@types/jest": "^26.0.9",
7878
"@types/lodash": "^4.14.137",
7979
"@types/react": "^16.9.2",
8080
"@types/react-router": "^3.0.4",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`test SlidePane should render correct 1`] = `
4+
<div>
5+
<div
6+
class="dtc-slide-pane"
7+
style="top: 0px; color: red; background: rgb(255, 124, 18);"
8+
>
9+
<div
10+
class="dtc-slide-pane-conent"
11+
data-testid="slidepane_container"
12+
style="display: block; height: 100%;"
13+
>
14+
<div>
15+
<h1>
16+
success
17+
</h1>
18+
</div>
19+
</div>
20+
<span
21+
class="dtc-slide-pane-toggle"
22+
data-testid="slidepane_action"
23+
>
24+
<i
25+
aria-label="icon: double-right"
26+
class="anticon anticon-double-right"
27+
>
28+
<svg
29+
aria-hidden="true"
30+
class=""
31+
data-icon="double-right"
32+
fill="currentColor"
33+
focusable="false"
34+
height="1em"
35+
viewBox="64 64 896 896"
36+
width="1em"
37+
>
38+
<path
39+
d="M533.2 492.3L277.9 166.1c-3-3.9-7.7-6.1-12.6-6.1H188c-6.7 0-10.4 7.7-6.3 12.9L447.1 512 181.7 851.1A7.98 7.98 0 0 0 188 864h77.3c4.9 0 9.6-2.3 12.6-6.1l255.3-326.1c9.1-11.7 9.1-27.9 0-39.5zm304 0L581.9 166.1c-3-3.9-7.7-6.1-12.6-6.1H492c-6.7 0-10.4 7.7-6.3 12.9L751.1 512 485.7 851.1A7.98 7.98 0 0 0 492 864h77.3c4.9 0 9.6-2.3 12.6-6.1l255.3-326.1c9.1-11.7 9.1-27.9 0-39.5z"
40+
/>
41+
</svg>
42+
</i>
43+
</span>
44+
</div>
45+
</div>
46+
`;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import SlidePane from '../index';
3+
import { render } from '@testing-library/react';
4+
import '@testing-library/jest-dom/extend-expect';
5+
6+
7+
describe('test SlidePane ', () => {
8+
const expectValues = {
9+
children:(<div>
10+
<h1>success</h1>
11+
</div>),
12+
visible:true,
13+
style:{color:'red',background:'#FF7C12'},
14+
}
15+
test('should render correct', () => {
16+
const {container,getByTestId}=render(<SlidePane
17+
children={expectValues.children}
18+
visible={expectValues.visible}
19+
style={expectValues.style}
20+
/>)
21+
expect(container.firstChild).toHaveStyle(expectValues.style);
22+
const oDiv = getByTestId('slidepane_container');
23+
expect(oDiv).not.toBeNull();
24+
expect(oDiv).toHaveStyle('display:block');
25+
expect(oDiv.innerHTML).toEqual("<div><h1>success</h1></div>");
26+
expect(container).toMatchSnapshot();
27+
})
28+
test('should be invisible', () => {
29+
const {getByTestId}=render(<SlidePane
30+
children={expectValues.children}
31+
visible={false}
32+
/>)
33+
const oDiv = getByTestId('slidepane_container');
34+
expect(oDiv).toHaveStyle('display:none');
35+
})}
36+
)

src/components/slidePane/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ class SlidePane extends React.Component<SlidePaneProps, any> {
3535

3636
return (
3737
<div className={ classes } style={myStyle} >
38-
<div className={`${slidePrefixCls}-conent`} style={{ display: visible ? 'block' : 'none', height: '100%' }}>
38+
<div className={`${slidePrefixCls}-conent`}
39+
data-testid="slidepane_container"
40+
style={{ display: visible ? 'block' : 'none', height: '100%' }}>
3941
{ children }
4042
</div>
41-
<span className={`${slidePrefixCls}-toggle`} onClick={onClose} {...{ onClick: onClose }}>
43+
<span className={`${slidePrefixCls}-toggle`} data-testid="slidepane_action" onClick={onClose} {...{ onClick: onClose }}>
4244
<Icon type="double-right" />
4345
</span>
4446
</div>

tsconfig.build.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"compilerOptions": {
3-
"outDir": "lib",
4-
"module": "esnext",
5-
"target": "es5",
6-
"declaration": true,
7-
"jsx": "react",
8-
"moduleResolution":"Node",
9-
"keyofStringsOnly": true,
10-
"allowSyntheticDefaultImports": true,
11-
"experimentalDecorators": true
12-
},
13-
"include": ["src/components"],
14-
"exclude": ["node_modules", "build", "scripts", "**/__tests__/*.test.tsx",]
15-
}
2+
"compilerOptions": {
3+
"outDir": "lib",
4+
"module": "esnext",
5+
"target": "es5",
6+
"declaration": true,
7+
"jsx": "react",
8+
"moduleResolution": "Node",
9+
"keyofStringsOnly": true,
10+
"allowSyntheticDefaultImports": true,
11+
"experimentalDecorators": true
12+
},
13+
"include": ["src/components"],
14+
"exclude": ["node_modules", "build", "scripts", "**/__tests__/*.test.tsx"]
15+
}

0 commit comments

Comments
 (0)