Skip to content

Commit e4a2d22

Browse files
update index.test.js
1 parent 24d2a65 commit e4a2d22

File tree

1 file changed

+191
-2
lines changed

1 file changed

+191
-2
lines changed

src/index.test.js

Lines changed: 191 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ describe("actions", () => {
8181
});
8282
return act(() => {
8383
return _api.select('2').then(result => {
84-
expect(typeof result != 'undefined').toBe(true);
84+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
8585
return _api.close('2').then(result => {
86-
expect(typeof result != 'undefined').toBe(true);
86+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
8787
});
8888
});
8989
});
@@ -169,6 +169,195 @@ describe("actions", () => {
169169
expect(op.onChange.mock.calls.length).toBe(0);
170170
expect(op.onInit.mock.calls.length).toBe(3);
171171
});
172+
test('select a tab twice', () => {
173+
let _api;
174+
expect.assertions(3);
175+
act(() => {
176+
const App = function (props) {
177+
const [Tablist, Panellist, api] = useDynTabs(op);
178+
_api = api;
179+
return (
180+
<div>
181+
<Tablist></Tablist>
182+
<Panellist></Panellist>
183+
</div>
184+
);
185+
};
186+
render(<App></App>, container);
187+
});
188+
return act(() => {
189+
return _api.select('1').then(result => {
190+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
191+
expect(op.onChange.mock.calls.length === 0).toBe(true);
192+
expect(op.onInit.mock.calls.length === 2).toBe(true);
193+
});
194+
});
195+
});
196+
test('selecting none existent tab', () => {
197+
let _api;
198+
expect.assertions(5);
199+
act(() => {
200+
const App = function (props) {
201+
const [Tablist, Panellist, api] = useDynTabs(op);
202+
_api = api;
203+
return (
204+
<div>
205+
<Tablist></Tablist>
206+
<Panellist></Panellist>
207+
</div>
208+
);
209+
};
210+
render(<App></App>, container);
211+
});
212+
return act(() => {
213+
return _api.select('3').then(result => {
214+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
215+
expect(document.querySelector('.rc-dyn-tabs-selected') == null).toBe(true);
216+
expect(_api.getCopyData().selectedTabID === '3').toBe(true);
217+
expect(op.onChange.mock.calls.length === 1).toBe(true);
218+
expect(op.onInit.mock.calls.length === 2).toBe(true);
219+
});
220+
});
221+
});
222+
test('calling select method with falsy value as a parameter', () => {
223+
let _api;
224+
expect.assertions(6);
225+
act(() => {
226+
const App = function (props) {
227+
const [Tablist, Panellist, api] = useDynTabs(op);
228+
_api = api;
229+
return (
230+
<div>
231+
<Tablist></Tablist>
232+
<Panellist></Panellist>
233+
</div>
234+
);
235+
};
236+
render(<App></App>, container);
237+
});
238+
return act(() => {
239+
try {
240+
_api.select();
241+
_api.select(undefined);
242+
} catch (er) {
243+
expect(_api.getCopyData().selectedTabID === '1').toBe(true);
244+
expect(op.onChange.mock.calls.length === 0).toBe(true);
245+
expect(op.onInit.mock.calls.length === 1).toBe(true);
246+
}
247+
return _api.select(null).then(result => {
248+
expect(op.onChange.mock.calls.length === 1).toBe(true);
249+
expect(op.onInit.mock.calls.length === 2).toBe(true);
250+
expect(_api.getCopyData().selectedTabID === null).toBe(true);
251+
});
252+
});
253+
});
254+
test('close a none opened tab', () => {
255+
let _api;
256+
expect.assertions(3);
257+
act(() => {
258+
const App = function (props) {
259+
const [Tablist, Panellist, api] = useDynTabs(op);
260+
_api = api;
261+
return (
262+
<div>
263+
<Tablist></Tablist>
264+
<Panellist></Panellist>
265+
</div>
266+
);
267+
};
268+
render(<App></App>, container);
269+
});
270+
return act(() => {
271+
return _api.close('4').then(result => {
272+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
273+
expect(op.onChange.mock.calls.length === 0).toBe(true);
274+
expect(op.onInit.mock.calls.length === 2).toBe(true);
275+
});
276+
});
277+
});
278+
test('calling close method with falsy value as a parameter', () => {
279+
let _api;
280+
expect.assertions(6);
281+
act(() => {
282+
const App = function (props) {
283+
const [Tablist, Panellist, api] = useDynTabs(op);
284+
_api = api;
285+
return (
286+
<div>
287+
<Tablist></Tablist>
288+
<Panellist></Panellist>
289+
</div>
290+
);
291+
};
292+
render(<App></App>, container);
293+
});
294+
return act(() => {
295+
try {
296+
_api.close();
297+
_api.close(undefined);
298+
} catch (er) {
299+
expect(_api.getCopyData().selectedTabID === '1').toBe(true);
300+
expect(op.onChange.mock.calls.length === 0).toBe(true);
301+
expect(op.onInit.mock.calls.length === 1).toBe(true);
302+
}
303+
return _api.close(null).then(result => {
304+
expect(op.onChange.mock.calls.length === 0).toBe(true);
305+
expect(op.onInit.mock.calls.length === 2).toBe(true);
306+
expect(_api.getCopyData().openTabIDs.length === 2).toBe(true);
307+
});
308+
});
309+
});
310+
test('open a tab twice', () => {
311+
let _api;
312+
expect.assertions(4);
313+
act(() => {
314+
const App = function (props) {
315+
const [Tablist, Panellist, api] = useDynTabs(op);
316+
_api = api;
317+
return (
318+
<div>
319+
<Tablist></Tablist>
320+
<Panellist></Panellist>
321+
</div>
322+
);
323+
};
324+
render(<App></App>, container);
325+
});
326+
return act(() => {
327+
return _api.open(op.tabs[0]).then(result => {
328+
expect(result.hasOwnProperty('currentData') && result.hasOwnProperty('instance')).toBe(true);
329+
expect(op.onChange.mock.calls.length === 0).toBe(true);
330+
expect(op.onInit.mock.calls.length === 2).toBe(true);
331+
expect(_api.getCopyData().openTabIDs.length === 2).toBe(true);
332+
});
333+
});
334+
});
335+
test('calling open method with falsy value as a parameter', () => {
336+
let _api;
337+
expect.assertions(3);
338+
act(() => {
339+
const App = function (props) {
340+
const [Tablist, Panellist, api] = useDynTabs(op);
341+
_api = api;
342+
return (
343+
<div>
344+
<Tablist></Tablist>
345+
<Panellist></Panellist>
346+
</div>
347+
);
348+
};
349+
render(<App></App>, container);
350+
});
351+
try {
352+
_api.open();
353+
_api.open(undefined);
354+
_api.open(null);
355+
} catch (er) {
356+
expect(_api.getCopyData().openTabIDs.length === 2).toBe(true);
357+
expect(op.onChange.mock.calls.length === 0).toBe(true);
358+
expect(op.onInit.mock.calls.length === 1).toBe(true);
359+
}
360+
});
172361
});
173362
describe("calling some action inside the events options", () => {
174363
let _api;

0 commit comments

Comments
 (0)