From 1994c98063c27a41797dec01f2ca9fcbe33ceab0 Mon Sep 17 00:00:00 2001 From: Israel Lavi Date: Mon, 21 May 2018 17:42:00 +0300 Subject: init commit onap ui Change-Id: I1dace78817dbba752c550c182dfea118b4a38646 Issue-ID: SDC-1350 Signed-off-by: Israel Lavi --- test/react/Tabs.spec.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/react/Tabs.spec.js (limited to 'test/react/Tabs.spec.js') diff --git a/test/react/Tabs.spec.js b/test/react/Tabs.spec.js new file mode 100644 index 0000000..9906708 --- /dev/null +++ b/test/react/Tabs.spec.js @@ -0,0 +1,55 @@ +import React from 'react'; +import Tab from '../../src/react/Tab.js'; +import Tabs from '../../src/react/Tabs.js'; + +import renderer from 'react-test-renderer'; +import {mount} from 'enzyme'; + +class TabsForm extends React.Component { + constructor(props) { + super(props); + this.state = {tabId: '1'}; + + this.handleChange = this.handleChange.bind(this); + } + + handleChange(val) { + this.setState({tabId: val}); + } + + render() { + return ( +
+
+ this.tabsInst = tabs} activeTab={this.state.tabId} onTabClick={this.handleChange} > + Tab #1 + Tab #2 + Tab #3 + +
+ +
+ ); + } +} + +describe('Tabs', () => { + + test('Tabs - basic rendering', () => { + const tabs = renderer.create().toJSON(); + expect(tabs).toMatchSnapshot(); + }); + + test('Tabs - when active tab id is changed, the respective tab is shown', () => { + const tabs = mount(); + expect(tabs.instance().tabsInst.props.activeTab).toEqual('1'); + expect(tabs.find('.sdc-tab-content').text()).toEqual('Tab #1'); + expect(tabs.find('li[data-test-id="1"]').hasClass('sdc-tab-active')).toBeTruthy(); + tabs.find('li[data-test-id="2"]').simulate('click'); + expect(tabs.instance().tabsInst.props.activeTab).toEqual('2'); + expect(tabs.find('li[data-test-id="2"]').hasClass('sdc-tab-active')).toBeTruthy(); + expect(tabs.find('li[data-test-id="1"]').hasClass('sdc-tab-active')).not.toBeTruthy(); + expect(tabs.find('.sdc-tab-content').text()).toEqual('Tab #2'); + }); + +}); -- cgit 1.2.3-korg