Skip to content

Commit 180f848

Browse files
update panel.test.js : create snapshot
for lazy panels
1 parent deb723e commit 180f848

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

src/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ describe('apply multiple actions : ', () => {
177177
});
178178
});
179179
describe('lazy tabs : ', () => {
180-
const Panel = React.lazy(() => import('./mock/mock-lazy-panel-1.js'));
181180
const LazyPanel = () => {
181+
const Panel = React.lazy(() => import('./mock/mock-lazy-panel-1.js'));
182182
return (
183183
<React.Suspense fallback={<p>loading...</p>}>
184184
<Panel></Panel>

src/panel/__snapshots__/panel.test.js.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,47 @@ exports[`panel structure : default options 1`] = `
119119
</div>
120120
`;
121121

122+
exports[`panel structure : lazy panels 1`] = `
123+
<div>
124+
<div
125+
className="rc-dyn-tabs-panel"
126+
tab-id="1"
127+
>
128+
<p>
129+
lazy panel 1
130+
</p>
131+
</div>
132+
<div
133+
className="rc-dyn-tabs-panel rc-dyn-tabs-selected"
134+
tab-id="2"
135+
>
136+
<p>
137+
lazy panel 2
138+
</p>
139+
</div>
140+
<div
141+
className="rc-dyn-tabs-panel"
142+
tab-id="3"
143+
>
144+
<p>
145+
lazy panel 3
146+
</p>
147+
</div>
148+
<div
149+
className="rc-dyn-tabs-panel"
150+
tab-id="4"
151+
>
152+
<p>
153+
loading...
154+
</p>
155+
</div>
156+
<div
157+
className="rc-dyn-tabs-panel"
158+
tab-id="5"
159+
/>
160+
</div>
161+
`;
162+
122163
exports[`panel structure : rtl and none accessibility options 1`] = `
123164
<div>
124165
<div

src/panel/panel.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ const getDefaultOptions = () => ({
3434
{id: '5', title: 'tab5', panelComponent: <span>panel 6</span>},
3535
],
3636
});
37-
const setMockUseContext = (op = {}) => {
37+
const setMockUseContext = (op = {}, onCreateInstance = () => {}) => {
3838
const defaultOp = getDefaultOptions();
3939
const instance = new Api({options: Object.assign({}, defaultOp, op)});
40+
onCreateInstance(instance);
4041
React.useContext = jest.fn(() => instance);
4142
};
4243
beforeAll(() => {
@@ -130,4 +131,40 @@ describe('panel structure : ', () => {
130131
.toJSON();
131132
expect(tree).toMatchSnapshot();
132133
});
134+
test('lazy panels', () => {
135+
setMockUseContext({accessibility: false}, (instance) => {
136+
instance.state.selectedTabID = '1';
137+
instance.activedTabsHistory.tabsId = ['3', '4'];
138+
instance.getTab = (id) => ({
139+
lazy: true,
140+
panelComponent: () => {
141+
let LazyPanel;
142+
if (id === '4') {
143+
LazyPanel = (props) => {
144+
const Panel = React.lazy(() => import('../mock/mock-lazy-panel-1.js'));
145+
return (
146+
<React.Suspense fallback={<p>loading...</p>}>
147+
<Panel></Panel>
148+
</React.Suspense>
149+
);
150+
};
151+
return <LazyPanel></LazyPanel>;
152+
}
153+
return <p>{`lazy panel ${id}`}</p>;
154+
},
155+
});
156+
});
157+
const tree = renderer
158+
.create(
159+
<div>
160+
<Panel id="1" selectedTabID="2"></Panel>
161+
<Panel id="2" selectedTabID="2"></Panel>
162+
<Panel id="3" selectedTabID="2"></Panel>
163+
<Panel id="4" selectedTabID="2"></Panel>
164+
<Panel id="5" selectedTabID="2"></Panel>
165+
</div>,
166+
)
167+
.toJSON();
168+
expect(tree).toMatchSnapshot();
169+
});
133170
});

0 commit comments

Comments
 (0)