-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Button): convert functional Button to class
* convert functional Button component to class to handle focus on click * add Button tests * add Button story to storybook * replace inline render functions from Modal with bound class functions
- Loading branch information
1 parent
82a2129
commit 9690fda
Showing
5 changed files
with
156 additions
and
36 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,15 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
/* eslint-disable no-console */ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import Button from './index'; | ||
|
||
storiesOf('Button', module) | ||
.add('basic usage', () => ( | ||
<Button | ||
label="Click me and check the console!" | ||
onClick={action('button-click')} | ||
/> | ||
)); |
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,39 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import Button from './index'; | ||
|
||
const defaultProps = { | ||
label: 'Click me!', | ||
}; | ||
|
||
describe('<Button />', () => { | ||
let wrapper; | ||
let button; | ||
|
||
beforeEach(() => { | ||
wrapper = mount( | ||
<Button | ||
{...defaultProps} | ||
/>, | ||
); | ||
|
||
button = wrapper.find('button'); | ||
}); | ||
it('renders', () => { | ||
expect(button).toHaveLength(1); | ||
}); | ||
it('puts focus on button on click', () => { | ||
expect(button.matchesElement(document.activeElement)).toEqual(false); | ||
button.simulate('click'); | ||
expect(button.at(0).matchesElement(document.activeElement)).toEqual(true); | ||
}); | ||
it('calls onClick prop on click', () => { | ||
const onClickSpy = jest.fn(); | ||
wrapper.setProps({ onClick: onClickSpy }); | ||
|
||
expect(onClickSpy).toHaveBeenCalledTimes(0); | ||
button.simulate('click'); | ||
expect(onClickSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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