-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from n7best/master
component tests
- Loading branch information
Showing
15 changed files
with
613 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*global before*/ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import assert from 'assert'; | ||
import WeUI from '../src/index'; | ||
var jsdom = require('jsdom'); | ||
|
||
const {ActionSheet, Mask} = WeUI; | ||
const menus = [{ | ||
label: '拍照', | ||
className: 'customClassName1' | ||
}, { | ||
label: '从相册中选取', | ||
className: 'customClassName2' | ||
}]; | ||
const actions = [{ | ||
label: '取消', | ||
className: 'customClassName' | ||
}, { | ||
label: '确定' | ||
}]; | ||
|
||
const androidUA = 'Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30'; | ||
const iosUA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25'; | ||
|
||
describe('<ActionSheet></ActionSheet>', ()=> { | ||
[androidUA, iosUA].map(userAgent=>{ | ||
['ios', 'android', undefined].map(type => { | ||
[undefined, null, true, false].map((show) => { | ||
[null, sinon.spy()].map( onRequestClose => { | ||
describe(`<ActionSheet menus='${menus}' actions='${actions}' show='${show}' onRequestClose='${onRequestClose}' type='${type}' />`, ()=> { | ||
|
||
before(() => { | ||
global.document = jsdom.jsdom('<!DOCTYPE html><html><head></head><body></body></html>', { userAgent: userAgent }); | ||
global.window = document.defaultView; | ||
global.navigator = { userAgent: userAgent }; | ||
//console.log('test', window.navigator.userAgent) | ||
}); | ||
|
||
const wrapper = mount( | ||
<ActionSheet menus={menus} actions={actions} show={show} onRequestClose={onRequestClose} type={type}/> | ||
); | ||
|
||
const wrapperInstance = wrapper.instance(); | ||
|
||
it('should render ActionSheet', () => { | ||
assert(wrapperInstance instanceof ActionSheet); | ||
}); | ||
|
||
it(`should have a hidden <Mask></Mask> when 'show' prop is false or undefined`, ()=> { | ||
const mask = wrapper.find(Mask) | ||
if (show) { | ||
assert(mask.prop('style').display === 'block'); | ||
} | ||
else { | ||
assert(mask.prop('style').display === 'none'); | ||
} | ||
}); | ||
|
||
it(`should have 'onRequestClose' event on Mask when 'show' prop is true`, ()=> { | ||
if (show && onRequestClose) { | ||
wrapper.find(Mask).simulate('click'); | ||
assert(onRequestClose.calledOnce === true); | ||
} | ||
}); | ||
|
||
it(`should have 'weui_actionsheet_toggle' class name when 'show' prop is true`, ()=> { | ||
const actionSheet = wrapper.find('.weui-actionsheet'); | ||
if (show) { | ||
assert(actionSheet.hasClass(`weui-actionsheet_toggle`)); | ||
} | ||
else { | ||
assert(!actionSheet.hasClass(`weui-actionsheet_toggle`)); | ||
} | ||
}); | ||
|
||
it(`should render ${menus.length} menu items `, ()=> { | ||
const menuItems = wrapper.find('.weui-actionsheet__menu').find('.weui-actionsheet__cell'); | ||
assert(menuItems.length === menus.length); | ||
|
||
menuItems.map((menuItem, index)=> { | ||
const menu = menus[index]; | ||
assert(menuItem.text() === menu.label); | ||
menu.className && assert(menuItem.hasClass(menu.className)); | ||
}); | ||
}); | ||
|
||
it(`should render ${actions.length} actions`, ()=> { | ||
const actionItems = wrapper.find('.weui-actionsheet__action').find('.weui-actionsheet__cell'); | ||
assert(actionItems.length === actions.length); | ||
|
||
actionItems.map((actionItem, index)=> { | ||
const action = actions[index]; | ||
assert(actionItem.text() === action.label); | ||
action.className && assert(actionItem.hasClass(action.className)); | ||
}); | ||
}); | ||
|
||
if(type == 'android'){ | ||
it('should have "weui-skin_android" class on main wrapper', ()=> { | ||
assert(wrapper.find('div').first().hasClass('weui-skin_android')); | ||
}); | ||
} | ||
|
||
if(!type && userAgent == androidUA) { | ||
wrapper.setState({ isAndroid: true }) | ||
it(`when no type define, should detect android and have "weui-skin_android" class on main wrapper`, ()=> { | ||
assert(wrapper.find('div').first().hasClass('weui-skin_android')); | ||
}); | ||
} | ||
|
||
}); | ||
}) | ||
}); | ||
}) | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import assert from 'assert'; | ||
import WeUI from '../src/index'; | ||
|
||
const { Article } = WeUI; | ||
|
||
describe('<ActionSheet></ActionSheet>', ()=> { | ||
[undefined, null, '', 'custom_class'].map((clazz)=> { | ||
describe('<Article className="${clazz}"></Article>', ()=> { | ||
const content = ( | ||
<div> | ||
<h1>大标题</h1> | ||
<section> | ||
<h2 className="title">章标题</h2> | ||
<section> | ||
<h3>1.1 节标题</h3> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | ||
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
consequat. Duis aute</p> | ||
</section> | ||
<section> | ||
<h3>1.2 节标题</h3> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | ||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non | ||
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
</section> | ||
</section> | ||
</div> | ||
); | ||
const wrapper = shallow( | ||
<Article className={clazz}> | ||
{content} | ||
</Article> | ||
); | ||
|
||
it('should render <Article></Article> component', () => { | ||
assert(wrapper.instance() instanceof Article); | ||
}); | ||
|
||
it(`should have class name 'weui-article'`, ()=> { | ||
assert(wrapper.hasClass(`weui-article`)); | ||
}); | ||
|
||
it(`should have custom class name ${clazz}`, ()=> { | ||
if (clazz) { | ||
assert(wrapper.hasClass(clazz)); | ||
} | ||
}); | ||
|
||
it(`should have children`, ()=> { | ||
assert(shallow(content).html() === wrapper.children().html()); | ||
}); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import assert from 'assert'; | ||
import WeUI from '../src/index'; | ||
|
||
const { ButtonArea, Button } = WeUI; | ||
|
||
describe('<ButtonArea></ButtonArea>', () => { | ||
[undefined, null, '', 'vertical', 'horizontal'].map((direction) => { | ||
[undefined, null, '', 'custom_class'].map((className) => { | ||
describe(`<ButtonArea className="${className} direction="${direction}></ButtonArea>`, () => { | ||
const child = <Button>确定</Button>; | ||
const wrapper = shallow( | ||
<ButtonArea className={className} direction={direction}> | ||
{child} | ||
</ButtonArea> | ||
); | ||
|
||
it(`should render a <ButtonArea></ButtonArea> component`, () => { | ||
assert(wrapper.instance() instanceof ButtonArea); | ||
}); | ||
|
||
it(`should have 'weui-btn-area' class name`, () => { | ||
assert(wrapper.hasClass(`weui-btn-area`)); | ||
}); | ||
|
||
it(`should have custom class name ${className}`, () => { | ||
if (className) { | ||
assert(wrapper.hasClass(`${className}`)); | ||
} | ||
}); | ||
|
||
it(`should have 'weui-btn-area_inline' when direction equal 'horizontal'`, () => { | ||
if (direction === 'horizontal') { | ||
assert(wrapper.hasClass(`weui-btn-area_inline`)); | ||
} | ||
else { | ||
assert(!wrapper.hasClass(`weui-btn-area_inline`)); | ||
} | ||
}); | ||
|
||
it(`should have children`, () => { | ||
assert(wrapper.find(Button).html() === shallow(child).html()); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.