Skip to content

Commit ebab164

Browse files
committed
tab test
1 parent 1171193 commit ebab164

File tree

1 file changed

+116
-1
lines changed

1 file changed

+116
-1
lines changed

test/tab.js

+116-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,116 @@
1-
//needs to refresh tabs change
1+
import React from 'react';
2+
import { mount, shallow } from 'enzyme';
3+
import assert from 'assert';
4+
import sinon from 'sinon';
5+
import WeUI from '../src/index';
6+
7+
const { Tab, TabBody, TabBodyItem, NavBar, NavBarItem, TabBar, TabBarItem, TabBarLabel, TabBarIcon } = WeUI;
8+
9+
describe('<Tab></Tab>', ()=>{
10+
11+
describe('Components should render all related weui class', ()=> {
12+
it('TabBody render weui-tab__panel', ()=> {
13+
assert( shallow(<TabBody/>).hasClass('weui-tab__panel') )
14+
})
15+
16+
it('TabBodyItem render weui-tab__bd-item', ()=> {
17+
assert( shallow(<TabBodyItem/>).hasClass('weui-tab__bd-item') )
18+
})
19+
20+
it('NavBar render weui-navbar', ()=> {
21+
assert( shallow(<NavBar/>).hasClass('weui-navbar') )
22+
})
23+
24+
it('NavBarItem render weui-navbar__item', ()=> {
25+
assert( shallow(<NavBarItem/>).hasClass('weui-navbar__item') )
26+
assert( shallow(<NavBarItem active/>).hasClass('weui-bar__item_on') )
27+
})
28+
29+
it('TabBar render weui-tabbar', ()=> {
30+
assert( shallow(<TabBar/>).hasClass('weui-tabbar') )
31+
})
32+
33+
it('TabBarItem render weui-tabbar__item', ()=> {
34+
assert( shallow(<TabBarItem/>).hasClass('weui-tabbar__item') )
35+
assert( shallow(<TabBarItem active/>).hasClass('weui-bar__item_on') )
36+
})
37+
38+
it('TabBarLabel render weui-tabbar__label', ()=> {
39+
assert( shallow(<TabBarLabel/>).hasClass('weui-tabbar__label') )
40+
})
41+
42+
it('TabBarIcon render weui-tabbar__icon', ()=> {
43+
assert( shallow(<TabBarIcon/>).hasClass('weui-tabbar__icon') )
44+
})
45+
})
46+
47+
it('should render Tab Component', ()=>{
48+
49+
const wrapper = mount(
50+
<Tab />
51+
)
52+
53+
assert(wrapper.instance() instanceof Tab)
54+
assert(wrapper.find('.weui-tab').length > 0)
55+
})
56+
57+
it('should auto mapping NavBar', ()=>{
58+
const wrapper = mount(
59+
<Tab type="navbar">
60+
<NavBarItem label="Nav1">test</NavBarItem>
61+
<NavBarItem label="Nav2">test2</NavBarItem>
62+
</Tab>
63+
)
64+
65+
assert(wrapper.find(NavBar).length > 0)
66+
assert(wrapper.find(NavBar).find(NavBarItem).length == 2)
67+
assert(wrapper.find(TabBody).length == 1)
68+
assert(wrapper.find(TabBody).find(TabBodyItem).length == 2)
69+
assert(wrapper.find(TabBody).find(TabBodyItem).first().text() == 'test')
70+
assert(wrapper.find(TabBody).find(TabBodyItem).last().text() == 'test2')
71+
assert(wrapper.find(TabBody).find(TabBodyItem).first().prop('active') == true)
72+
})
73+
74+
it('should auto mapping TabBar', ()=>{
75+
76+
const wrapper = mount(
77+
<Tab type="tabbar">
78+
<TabBarItem label="Tab1" icon="pic">test</TabBarItem>
79+
<TabBarItem label="Tab2" icon="pic">test2</TabBarItem>
80+
</Tab>
81+
)
82+
83+
assert(wrapper.find(TabBar).length > 0)
84+
assert(wrapper.find(TabBar).find(TabBarItem).length == 2)
85+
assert(wrapper.find(TabBody).length == 1)
86+
assert(wrapper.find(TabBody).find(TabBodyItem).length == 2)
87+
assert(wrapper.find(TabBody).find(TabBodyItem).first().text() == 'test')
88+
assert(wrapper.find(TabBody).find(TabBodyItem).last().text() == 'test2')
89+
assert(wrapper.find(TabBody).find(TabBodyItem).first().prop('active') == true)
90+
})
91+
92+
it('should switch tab onClick and trigger onChange', ()=> {
93+
let spy = sinon.spy()
94+
const wrapper = mount(
95+
<Tab type="tabbar" onChange={spy}>
96+
<TabBarItem label="Tab1">test</TabBarItem>
97+
<TabBarItem label="Tab2">test2</TabBarItem>
98+
</Tab>
99+
)
100+
101+
assert(wrapper.find(TabBody).find(TabBodyItem).first().prop('active') == true)
102+
103+
wrapper.find(TabBar).find(TabBarItem).last().simulate('click')
104+
105+
assert(wrapper.find(TabBody).find(TabBodyItem).first().prop('active') == false)
106+
assert(wrapper.find(TabBody).find(TabBodyItem).last().prop('active') == true)
107+
108+
assert(spy.called)
109+
})
110+
111+
it('should return nothing with invalid type', ()=>{
112+
const wrapper = mount(<Tab type="haha" />)
113+
assert(wrapper.html() == null)
114+
})
115+
116+
})

0 commit comments

Comments
 (0)