forked from ant-design/ant-design-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add segmented-control test, ref ant-design#1274 (ant-design#1511)
- Loading branch information
1 parent
c541378
commit d2aa167
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
components/segmented-control/__tests__/__snapshots__/index.test.js.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SegmentedControl renders correctly 1`] = ` | ||
<RCTSegmentedControl | ||
enabled={true} | ||
onChange={[Function]} | ||
selectedIndex={0} | ||
style={ | ||
Array [ | ||
Object { | ||
"height": 28, | ||
}, | ||
undefined, | ||
] | ||
} | ||
tintColor="#108ee9" | ||
values={ | ||
Array [ | ||
"切换一", | ||
"切换二", | ||
] | ||
} | ||
/> | ||
`; |
33 changes: 33 additions & 0 deletions
33
components/segmented-control/__tests__/__snapshots__/index.test.web.js.snap
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,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SegmentedControl renders correctly 1`] = ` | ||
<div | ||
class="am-segment" | ||
role="tablist" | ||
> | ||
<div | ||
aria-disabled="false" | ||
aria-selected="true" | ||
class="am-segment-item am-segment-item-selected" | ||
role="tab" | ||
style="color:#fff;background-color:;border-color:;" | ||
> | ||
<div | ||
class="am-segment-item-inner" | ||
/> | ||
切换一 | ||
</div> | ||
<div | ||
aria-disabled="false" | ||
aria-selected="false" | ||
class="am-segment-item" | ||
role="tab" | ||
style="color:;background-color:#fff;border-color:;" | ||
> | ||
<div | ||
class="am-segment-item-inner" | ||
/> | ||
切换二 | ||
</div> | ||
</div> | ||
`; |
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,10 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import SegmentedControl from '../index'; | ||
|
||
describe('SegmentedControl', () => { | ||
it('renders correctly', () => { | ||
const tree = renderer.create(<SegmentedControl values={['切换一', '切换二']} />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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,33 @@ | ||
import React from 'react'; | ||
import { render, shallow } from 'enzyme'; | ||
import { renderToJson } from 'enzyme-to-json'; | ||
import SegmentedControl from '../index.web'; | ||
|
||
describe('SegmentedControl', () => { | ||
it('renders correctly', () => { | ||
const wrapper = render(<SegmentedControl values={['切换一', '切换二']} />); | ||
expect(renderToJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
it('check api', () => { | ||
const onValueChange = jest.fn(); | ||
const onChange = jest.fn(); | ||
const wrapper = shallow( | ||
<SegmentedControl values={['切换一', '切换二']} onValueChange={onValueChange} onChange={onChange} />, | ||
); | ||
expect(wrapper.find('.am-segment-item')).toHaveLength(2); | ||
expect(wrapper.find('.am-segment-item').at(0).hasClass('am-segment-item-selected')).toBeTruthy(); | ||
wrapper.find('.am-segment-item').at(1).simulate('click', {}); | ||
expect(onValueChange).toHaveBeenCalledWith('切换二'); | ||
expect(onChange).toHaveBeenCalledWith( | ||
{ | ||
nativeEvent: { | ||
selectedSegmentIndex: 1, | ||
value: '切换二', | ||
}, | ||
}, | ||
); | ||
expect(wrapper.find('.am-segment-item').at(0).hasClass('am-segment-item-selected')).toBeFalsy(); | ||
expect(wrapper.find('.am-segment-item').at(1).hasClass('am-segment-item-selected')).toBeTruthy(); | ||
}); | ||
}); |