|
| 1 | +/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | + |
| 5 | +import { mount } from 'enzyme'; |
| 6 | +import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap'; |
| 7 | +import classnames from 'classnames'; |
| 8 | +// Not sure if this is correct but didn't want to repeat a whole bunch of code. |
| 9 | +import TabsExample from '../docs/lib/examples/Tabs'; |
| 10 | + |
| 11 | +describe('Tabs', () => { |
| 12 | + it('should render', () => { |
| 13 | + let tab1 = mount(<TabsExample />); |
| 14 | + expect(tab1.find('.nav .nav-tabs').length).toBe(1); |
| 15 | + expect(tab1.find('.nav .nav-item').length).toBe(2); |
| 16 | + expect(tab1.find('.tab-content').length).toBe(1); |
| 17 | + expect(tab1.find('.tab-pane').length).toBe(2); |
| 18 | + }); |
| 19 | + it('should have tab1 as active', () => { |
| 20 | + let tab1 = mount(<TabsExample />); |
| 21 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(true); |
| 22 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(false); |
| 23 | + expect(tab1.find('.tab-content .tab-pane').at(0).hasClass('active')).toBe(true); |
| 24 | + }); |
| 25 | + it('should switch to tab2 as active when clicked', () => { |
| 26 | + let tab1 = mount(<TabsExample />); |
| 27 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(true); |
| 28 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(false); |
| 29 | + expect(tab1.find('.tab-content .tab-pane').at(0).hasClass('active')).toBe(true); |
| 30 | + tab1.find('.nav .nav-item .nav-link').at(1).simulate('click'); |
| 31 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(false); |
| 32 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(true); |
| 33 | + expect(tab1.find('.tab-content .tab-pane').at(1).hasClass('active')).toBe(true); |
| 34 | + tab1.find('.nav .nav-item .nav-link').at(0).simulate('click'); |
| 35 | + }); |
| 36 | + it('should show no active tabs if active tab id is unknown', () => { |
| 37 | + let tab1 = mount(<TabsExample />); |
| 38 | + const instance = tab1.instance(); |
| 39 | + expect(instance instanceof TabsExample).toBe(true); |
| 40 | + instance.toggle('3'); |
| 41 | + /* Not sure if this is what we want. Toggling to an unknown tab id should |
| 42 | + render all tabs as inactive and should show no content. |
| 43 | + This could be a warning during development that the user is not having a proper tab ids. |
| 44 | + NOTE: Should this be different? |
| 45 | + */ |
| 46 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(false); |
| 47 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(false); |
| 48 | + expect(tab1.find('.tab-content .tab-pane').at(0).hasClass('active')).toBe(false); |
| 49 | + }); |
| 50 | + it('should do nothing clicking on the same tab', () => { |
| 51 | + let tab1 = mount(<TabsExample />); |
| 52 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(true); |
| 53 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(false); |
| 54 | + expect(tab1.find('.tab-content .tab-pane').at(0).hasClass('active')).toBe(true); |
| 55 | + tab1.find('.nav .nav-item .nav-link').at(0).simulate('click'); |
| 56 | + expect(tab1.find('.nav .nav-item .nav-link').at(0).hasClass('active')).toBe(true); |
| 57 | + expect(tab1.find('.nav .nav-item .nav-link').at(1).hasClass('active')).toBe(false); |
| 58 | + expect(tab1.find('.tab-content .tab-pane').at(0).hasClass('active')).toBe(true); |
| 59 | + }); |
| 60 | +}); |
0 commit comments