Skip to content

Commit 45d750d

Browse files
create panelList.test.js
1 parent d071af3 commit 45d750d

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`PanelList structure : default options 1`] = `
4+
<div>
5+
<div
6+
className="rc-dyn-tabs-panellist rc-dyn-tabs-ltr"
7+
>
8+
<div
9+
aria-hidden={false}
10+
aria-labelledby="rc-dyn-tabs-l-1"
11+
className="rc-dyn-tabs-panel rc-dyn-tabs-selected"
12+
id="rc-dyn-tabs-p-1"
13+
role="tabpanel"
14+
tab-id="1"
15+
>
16+
<div />
17+
</div>
18+
<div
19+
aria-hidden={true}
20+
aria-labelledby="rc-dyn-tabs-l-2"
21+
className="rc-dyn-tabs-panel"
22+
id="rc-dyn-tabs-p-2"
23+
role="tabpanel"
24+
tab-id="2"
25+
>
26+
<div />
27+
</div>
28+
</div>
29+
</div>
30+
`;
31+
32+
exports[`PanelList structure : rtl option 1`] = `
33+
<div>
34+
<div
35+
className="rc-dyn-tabs-panellist rc-dyn-tabs-rtl"
36+
>
37+
<div
38+
aria-hidden={false}
39+
aria-labelledby="rc-dyn-tabs-l-1"
40+
className="rc-dyn-tabs-panel rc-dyn-tabs-selected"
41+
id="rc-dyn-tabs-p-1"
42+
role="tabpanel"
43+
tab-id="1"
44+
>
45+
<div />
46+
</div>
47+
<div
48+
aria-hidden={true}
49+
aria-labelledby="rc-dyn-tabs-l-2"
50+
className="rc-dyn-tabs-panel"
51+
id="rc-dyn-tabs-p-2"
52+
role="tabpanel"
53+
tab-id="2"
54+
>
55+
<div />
56+
</div>
57+
</div>
58+
</div>
59+
`;

src/panelList/panelList.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from "react"
2+
import { unmountComponentAtNode } from "react-dom";
3+
import PanelList from "./panelList.js";
4+
import renderer from 'react-test-renderer';
5+
import Api from '../utils/api/api.js';
6+
let container = document.createElement("div"), realUseContext;
7+
const getDefaultApi = () => ({
8+
tabs: [
9+
{ id: '1', title: 'tab1' },
10+
{ id: '2', title: 'tab2' },
11+
],
12+
selectedTabID: '1'
13+
});
14+
const setMockUseContext = (op = {}) => {
15+
const defaultOp = getDefaultApi();
16+
const instance = new (Api)({ options: Object.assign({}, defaultOp, op) });
17+
instance.openTabIDs = ['1', '2'];
18+
instance.selectedTabID = '1';
19+
React.useContext = jest.fn(() => instance);
20+
};
21+
beforeAll(() => {
22+
document.body.appendChild(container);
23+
realUseContext = React.useContext;
24+
});
25+
beforeEach(() => { });
26+
afterEach(() => {
27+
unmountComponentAtNode(container);
28+
container.innerHTML = "";
29+
React.useContext = realUseContext;
30+
});
31+
afterAll(() => {
32+
document.body.removeChild(container);
33+
container = null;
34+
});
35+
describe('PanelList structure : ', () => {
36+
test('default options', () => {
37+
setMockUseContext();
38+
const tree = renderer
39+
.create(<div>
40+
<PanelList></PanelList>
41+
</div>)
42+
.toJSON();
43+
expect(tree).toMatchSnapshot();
44+
});
45+
test('rtl option', () => {
46+
setMockUseContext({ direction: 'rtl' });
47+
const tree = renderer
48+
.create(<div>
49+
<PanelList></PanelList>
50+
</div>)
51+
.toJSON();
52+
expect(tree).toMatchSnapshot();
53+
});
54+
});
55+
56+

0 commit comments

Comments
 (0)