Skip to content

Commit ce277a0

Browse files
committed
feat: add Switch
1 parent 1650e5a commit ce277a0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Switch.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class AppSwitch extends Component {
8484

8585
return (
8686
<label className={classes}>
87-
<input type={type} className={inputClasses} onChange={this.toggle} checked={this.state.checked} defaultChecked={defaultChecked} name={name}
88-
required={required} disabled={disabled} value={value} />
87+
<input type={type} className={inputClasses} onChange={this.toggle} checked={this.state.checked} name={name} required={required} disabled={disabled} value={value} />
8988
<span className={sliderClasses} data-checked={dataOn} data-unchecked={dataOff}></span>
9089
</label>
9190
);

tests/Switch.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import expect from 'expect'
2+
import React from 'react'
3+
import {renderToStaticMarkup as render} from 'react-dom/server'
4+
5+
import { configure, mount } from 'enzyme'
6+
import Adapter from 'enzyme-adapter-react-16'
7+
import { spy } from 'sinon'
8+
9+
import AppSwitch from 'src/Switch'
10+
11+
configure({ adapter: new Adapter() });
12+
13+
describe('AppSwitch', () => {
14+
it('renders label with class="switch"', () => {
15+
expect(render(<AppSwitch />))
16+
.toContain('<label class="switch')
17+
});
18+
it('should call toggle', () => {
19+
const onChange = spy(AppSwitch.prototype, 'toggle');
20+
const event = {target: { checked: true }};
21+
const wrapper = mount(<AppSwitch outlineAlt label pill size="lg" />);
22+
expect(wrapper.find('input').props().checked).toBe(false);
23+
wrapper.find('input').simulate('change', event)
24+
expect(onChange.called).toBe(true);
25+
expect(wrapper.find('input').props().checked).toBe(true);
26+
27+
})
28+
})

0 commit comments

Comments
 (0)