-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
spartDev
committed
Aug 8, 2018
1 parent
cfbf48c
commit d83b18c
Showing
9 changed files
with
1,506 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# CheckBox | ||
|
||
### Usage | ||
|
||
```jsx | ||
import CheckBox from 'components/CheckBox'; | ||
|
||
// or | ||
|
||
import { CheckBox } from 'components'; | ||
``` | ||
|
||
<!-- STORY --> | ||
|
||
### Properties | ||
|
||
- `checked` - Whether the button is checked or not. | ||
- `disabled` - Whether the button is enabled or not. | ||
- `onChange` - Callback whence clicked. | ||
|
||
| propName | propType | defaultValue | isRequired | | ||
| ---------- | :------: | :----------: | :--------: | | ||
| `checked` | `bool` | `false` | - | | ||
| `disabled` | `bool` | `true` | - | | ||
| `onChange` | `func` | `() => {}` | - | | ||
|
||
### Example | ||
|
||
```jsx | ||
import CheckBox from 'components/CheckBox'; | ||
|
||
render() { | ||
return <CheckBox>Add sauce?</CheckBox> | ||
} | ||
``` |
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,32 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { withKnobs, boolean } from '@storybook/addon-knobs/react'; | ||
import { State, Store } from '@sambego/storybook-state'; | ||
|
||
import { CheckBox } from '../..'; | ||
|
||
const store = new Store({ | ||
checked: false, | ||
}); | ||
|
||
storiesOf('CheckBox', module) | ||
.addDecorator(withKnobs) | ||
.add('default', () => { | ||
const enabledValue = boolean('Enabled', true, 'state'); | ||
|
||
return ( | ||
<State store={store}> | ||
<CheckBox disabled={!enabledValue}>A really cool choice</CheckBox> | ||
</State> | ||
); | ||
}) | ||
.add('controlled', () => { | ||
const checkedValue = boolean('Checked', false, 'state'); | ||
const enabledValue = boolean('Enabled', true, 'state'); | ||
|
||
return ( | ||
<CheckBox checked={checkedValue} disabled={!enabledValue} onChange={() => {}}> | ||
What? | ||
</CheckBox> | ||
); | ||
}); |
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,78 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import 'jest-styled-components'; | ||
|
||
import CheckBox from '..'; | ||
import Theme from '../../Theme'; | ||
|
||
describe('<CheckBox />', () => { | ||
it('should render without a problem', () => { | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" /> | ||
</ThemeProvider>, | ||
); | ||
expect(render).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without a problem when checked and enabled', () => { | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked /> | ||
</ThemeProvider>, | ||
); | ||
expect(render).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without a problem when unchecked and enabled', () => { | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked={false} /> | ||
</ThemeProvider>, | ||
); | ||
expect(render).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without a problem when checked and disabled', () => { | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked disabled /> | ||
</ThemeProvider>, | ||
); | ||
expect(render).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without a problem when unchecked and disabled', () => { | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked={false} disabled /> | ||
</ThemeProvider>, | ||
); | ||
expect(render).toMatchSnapshot(); | ||
}); | ||
|
||
it('should call change handler when enabled', () => { | ||
const spy = jest.fn(); | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked onChange={spy} /> | ||
</ThemeProvider>, | ||
); | ||
render.simulate('click'); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not call change handler when disabled', () => { | ||
const spy = jest.fn(); | ||
const render = mount( | ||
<ThemeProvider theme={Theme}> | ||
<CheckBox id="test" checked disabled onChange={spy} /> | ||
</ThemeProvider>, | ||
); | ||
render.simulate('click'); | ||
|
||
expect(spy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.