Skip to content

Commit

Permalink
add test for switch, ref #1274
Browse files Browse the repository at this point in the history
  • Loading branch information
silentcloud committed Jun 30, 2017
1 parent 4164060 commit d4dbb50
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ exports[`renders ./components/list-view/demo/idxed-sticky.md correctly 1`] = `
style="position:absolute;top:0;left:0;right:0;"
>
<form
action="#"
class="am-search"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ exports[`renders ./components/list/demo/form.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`renders ./components/search-bar/demo/basic.md correctly 1`] = `
</div>
</div>
<form
action="#"
class="am-search"
>
<div
Expand Down Expand Up @@ -63,6 +64,7 @@ exports[`renders ./components/search-bar/demo/basic.md correctly 1`] = `
</div>
</div>
<form
action="#"
class="am-search"
>
<div
Expand Down Expand Up @@ -114,6 +116,7 @@ exports[`renders ./components/search-bar/demo/basic.md correctly 1`] = `
</div>
</div>
<form
action="#"
class="am-search"
>
<div
Expand Down Expand Up @@ -181,6 +184,7 @@ exports[`renders ./components/search-bar/demo/basic.md correctly 1`] = `
</div>
</div>
<form
action="#"
class="am-search am-search-start"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`SearchBar renders correctly 1`] = `
<form
action="#"
class="am-search"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -67,6 +68,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -101,6 +103,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
disabled=""
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox checkbox-disabled"
Expand Down Expand Up @@ -136,6 +139,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
disabled=""
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox checkbox-disabled"
Expand Down Expand Up @@ -169,6 +173,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -203,6 +208,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down
21 changes: 21 additions & 0 deletions components/switch/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Switch renders correctly 1`] = `
<RCTSwitch
disabled={false}
onChange={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onValueChange={[Function]}
style={
Array [
Object {
"height": 31,
"width": 51,
},
undefined,
]
}
value={true}
/>
`;
18 changes: 18 additions & 0 deletions components/switch/__tests__/__snapshots__/index.test.web.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SegmentedControl renders correctly 1`] = `
<label
class="am-switch"
>
<input
checked=""
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
/>
</label>
`;
10 changes: 10 additions & 0 deletions components/switch/__tests__/index.test.js
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 Switch from '../index';

describe('Switch', () => {
it('renders correctly', () => {
const tree = renderer.create(<Switch checked />).toJSON();
expect(tree).toMatchSnapshot();
});
});
20 changes: 20 additions & 0 deletions components/switch/__tests__/index.test.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Switch from '../index.web';

describe('SegmentedControl', () => {
it('renders correctly', () => {
const wrapper = render(<Switch checked />);
expect(renderToJson(wrapper)).toMatchSnapshot();
});

it('check api', () => {
const onChange = jest.fn();
const wrapper = shallow(<Switch checked onChange={onChange} />);
expect(wrapper.find('input').is('input[value="on"]')).toBeTruthy();
// I don't know why click/change doesn't change the value to `off`
// wrapper.find('input').simulate('click', { target: { checked: false } });
// expect(wrapper.find('input').is('input[value="off"]')).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions components/switch/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class Switch extends React.Component<SwitchProps, any> {
disabled={disabled}
checked={checked}
onChange={this.onChange}
value={checked ? 'on' : 'off'}
{...(!disabled ? { onClick: this.onClick } : {})}
{...globalProps}
/>
Expand Down

0 comments on commit d4dbb50

Please sign in to comment.