-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(popups): Add ReplyField component (#444)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f6f4580
commit f3b490c
Showing
5 changed files
with
82 additions
and
26 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,17 @@ | ||
import * as React from 'react'; | ||
import classnames from 'classnames'; | ||
|
||
export type Props = { | ||
className?: string; | ||
defaultValue?: string; | ||
onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void; | ||
onClick: (event: React.SyntheticEvent) => void; | ||
}; | ||
|
||
const ReplyField = (props: Props, ref: React.Ref<HTMLTextAreaElement>): JSX.Element => { | ||
const { className, ...rest } = props; | ||
|
||
return <textarea ref={ref} className={classnames('ba-TextArea', className)} {...rest} />; | ||
}; | ||
|
||
export default React.forwardRef(ReplyField); |
35 changes: 35 additions & 0 deletions
35
src/components/Popups/ReplyField/__tests__/ReplyField-test.tsx
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 @@ | ||
import React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import ReplyField, { Props } from '../ReplyField'; | ||
|
||
describe('components/Popups/ReplyField', () => { | ||
const defaults: Props = { | ||
className: 'ba-Popup-text', | ||
defaultValue: '', | ||
onChange: jest.fn(), | ||
onClick: jest.fn(), | ||
}; | ||
|
||
const getWrapper = (props = {}): ShallowWrapper => shallow(<ReplyField {...defaults} {...props} />); | ||
|
||
describe('event handlers', () => { | ||
test('should call onChange event', () => { | ||
const wrapper = getWrapper(); | ||
const textarea = wrapper.find('textarea'); | ||
|
||
textarea.simulate('change', 'test'); | ||
textarea.simulate('click', 'test'); | ||
|
||
expect(defaults.onChange).toHaveBeenCalledWith('test'); | ||
expect(defaults.onClick).toHaveBeenCalledWith('test'); | ||
}); | ||
}); | ||
|
||
describe('render()', () => { | ||
test('should render the textarea with right props', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.prop('className')).toBe('ba-TextArea ba-Popup-text'); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
export { default } from './ReplyField'; |
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