|
| 1 | +import Tabs from './tabs.js'; |
| 2 | +import React from 'react'; |
| 3 | +let obj, defaultPanelComponent; |
| 4 | +beforeEach(() => { |
| 5 | + obj = new (Tabs)(); |
| 6 | + defaultPanelComponent = function (props) { return <p></p> }; |
| 7 | +}); |
| 8 | +afterEach(() => { |
| 9 | + obj = null; |
| 10 | + defaultPanelComponent = null; |
| 11 | +}); |
| 12 | +describe('Tabs.prototype._addTab : ', () => { |
| 13 | + test('_addTab method should work correctly with empty object as a parameter', () => { |
| 14 | + const tabData = obj._addTab({}, { defaultPanelComponent }); |
| 15 | + expect(tabData.hasOwnProperty('title')).toBe(true); |
| 16 | + expect(tabData.hasOwnProperty('tooltip')).toBe(true); |
| 17 | + expect(typeof tabData.panelComponent === 'function').toBe(true); |
| 18 | + expect(tabData.closable === true).toBe(true); |
| 19 | + expect(tabData.hasOwnProperty('iconClass')).toBe(true); |
| 20 | + expect(tabData.disable === false).toBe(true); |
| 21 | + expect(typeof tabData.id === 'string').toBe(true); |
| 22 | + }); |
| 23 | + test('_addTab method should work correctly when is called with parameters', () => { |
| 24 | + const panelComponent = props => <p></p>; |
| 25 | + const tabData = obj._addTab({ |
| 26 | + id: '3', title: 'a', tooltip: 't', panelComponent, closable: false, iconClass: 'c', disable: true |
| 27 | + }, { defaultPanelComponent }); |
| 28 | + expect(tabData.title === 'a').toBe(true); |
| 29 | + expect(tabData.tooltip === 't').toBe(true); |
| 30 | + expect(tabData.panelComponent === panelComponent).toBe(true); |
| 31 | + expect(tabData.closable === false).toBe(true); |
| 32 | + expect(tabData.iconClass === 'c').toBe(true); |
| 33 | + expect(tabData.disable === true).toBe(true); |
| 34 | + expect(tabData.id === '3').toBe(true); |
| 35 | + }); |
| 36 | + test('_addTab method should convert a number id into string id', () => { |
| 37 | + const panelComponent = props => <p></p>; |
| 38 | + const tabData = obj._addTab({ id: 3 }, { defaultPanelComponent }); |
| 39 | + expect(tabData.id === '3').toBe(true); |
| 40 | + }); |
| 41 | + test('_addTab method should throw an error when is called with an none real object param', () => { |
| 42 | + expect.assertions(2); |
| 43 | + let tabData; |
| 44 | + try { |
| 45 | + tabData = obj._addTab([], { defaultPanelComponent }); |
| 46 | + } catch (er) { |
| 47 | + expect(typeof tabData === 'undefined').toBe(true); |
| 48 | + expect(er.message === 'tabData must be type of Object').toBe(true); |
| 49 | + } |
| 50 | + }); |
| 51 | + test('_addTab method should work correctly when is called with a react element as a panelComponent parameter', () => { |
| 52 | + const tabData = obj._addTab({ panelComponent: <div></div> }, { defaultPanelComponent }); |
| 53 | + expect(tabData.hasOwnProperty('title')).toBe(true); |
| 54 | + expect(tabData.hasOwnProperty('tooltip')).toBe(true); |
| 55 | + expect(typeof tabData.panelComponent === 'function').toBe(true); |
| 56 | + expect(tabData.closable === true).toBe(true); |
| 57 | + expect(tabData.hasOwnProperty('iconClass')).toBe(true); |
| 58 | + expect(tabData.disable === false).toBe(true); |
| 59 | + expect(typeof tabData.id === 'string').toBe(true); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | + |
0 commit comments