Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/wincloud_gateway/node_modules/reactstrap/src/__tests__/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import React from 'react';
import { shallow, mount } from 'enzyme';
import { TabContent, TabPane } from '../';
let activeTab = '1';
describe('Tabs', () => {
it('should render', () => {
activeTab = '1';
let tab1 = mount(
<TabContent activeTab={activeTab}>
<TabPane tabId="1">
Tab Content 1
</TabPane>
<TabPane tabId="2">
TabContent 2
</TabPane>
</TabContent>
);
expect(tab1.find('.tab-content').hostNodes().length).toBe(1);
expect(tab1.find('.tab-pane').hostNodes().length).toBe(2);
});
it('should have tab1 as active', () => {
activeTab = '1';
let tab1 = mount(
<TabContent activeTab={activeTab}>
<TabPane tabId="1">
Tab Content 1
</TabPane>
<TabPane tabId="2">
TabContent 2
</TabPane>
</TabContent>
);
expect(tab1.find('.tab-content .tab-pane').hostNodes().at(0).hasClass('active')).toBe(true);
});
it('should switch to tab2 as active when clicked', () => {
activeTab = '2';
let tab1 = mount(
<TabContent activeTab={activeTab}>
<TabPane tabId="1">
Tab Content 1
</TabPane>
<TabPane tabId="2">
TabContent 2
</TabPane>
</TabContent>
);
expect(tab1.find('.tab-content .tab-pane').hostNodes().at(1).hasClass('active')).toBe(true);
});
it('should not setState when the active tab does not change during a prop update', () => {
const tab1 = mount(<TabContent activeTab={1} />);
const instance = tab1.instance();
jest.spyOn(instance, 'setState');
tab1.setProps({ style: { textAlign: 'left' } });
expect(instance.setState).not.toHaveBeenCalled();
});
it('should show no active tabs if active tab id is unknown', () => {
activeTab = '3';
let tab1 = mount(
<TabContent activeTab={activeTab}>
<TabPane tabId="1">
Tab Content 1
</TabPane>
<TabPane tabId="2">
TabContent 2
</TabPane>
</TabContent>
);
/* Not sure if this is what we want. Toggling to an unknown tab id should
render all tabs as inactive and should show no content.
This could be a warning during development that the user is not having a proper tab ids.
NOTE: Should this be different?
*/
expect(tab1.find('.tab-content .tab-pane').hostNodes().at(0).hasClass('active')).toBe(false);
expect(tab1.find('.tab-content .tab-pane').hostNodes().at(1).hasClass('active')).toBe(false);
});
it('should call setState when the active tab does change during a prop update', () => {
const tab1 = mount(<TabContent activeTab={1} />);
expect(tab1.state().activeTab).toEqual(1);
tab1.setProps({ activeTab: 2 });
expect(tab1.state().activeTab).toEqual(2);
});
it('should render custom TabContent tag', () => {
const wrapper = shallow(
<TabContent tag="main" activeTab={activeTab}>
<TabPane tabId="1">
Tab Content 1
</TabPane>
<TabPane tabId="2">
TabContent 2
</TabPane>
</TabContent>
);
expect(wrapper.childAt(0).type()).toBe('main');
});
it('should render custom TabPane tag', () => {
const wrapper = mount(<TabPane tag="main" tabId="1">Tab Content 1</TabPane>, { context: {} });
expect(wrapper.childAt(0).type()).toBe('main');
});
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0061 ]-- |