diff --git a/src/components/App/__snapshots__/test.js.snap b/src/components/App/__snapshots__/test.js.snap index 6f8f900..5e067f6 100644 --- a/src/components/App/__snapshots__/test.js.snap +++ b/src/components/App/__snapshots__/test.js.snap @@ -3,7 +3,7 @@ exports[`App removing rendered expression 1`] = ` { + const { t } = useTranslation(); + const [ expr, exprUpdate ] = useState(props.expr); + const [ syntax, syntaxUpdate ] = useState(props.syntax); - state = { - expr: this.props.expr, - syntax: this.props.syntax - } - - handleSubmit = event => { + const handleExprChange = useCallback(event => { + exprUpdate(event.target.value); + }, [exprUpdate]); + const handleSyntaxChange = useCallback(event => { + syntaxUpdate(event.target.value); + }, [syntaxUpdate]); + const handleSubmit = useCallback(event => { event.preventDefault(); - const { expr, syntax } = this.state; - - this.props.onSubmit({ expr, syntax }); - } - - handleKeyPress = event => { + onSubmit({ expr, syntax }); + }, [expr, syntax, onSubmit]); + const handleKeyPress = useCallback(event => { if (event.charCode === 13 && event.shiftKey) { - this.handleSubmit(event); + handleSubmit(event); } - } + }, [handleSubmit]); - handleChange = event => this.setState({ - [event.target.name]: event.target.value - }) + return
+
+ + +
+ + +
+ { children } +
+
; +}; - render() { - const { - syntaxList, - children, - t - } = this.props; - const { expr, syntax } = this.state; +Form.propTypes = { + expr: PropTypes.string, + syntax: PropTypes.string, + syntaxList: PropTypes.arrayOf(PropTypes.shape({ + id: PropTypes.string, + label: PropTypes.string + })), + onSubmit: PropTypes.func.isRequired, + children: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.node), + PropTypes.node + ]) +}; - return
-
- - -
- - -
- { children } -
-
; - } -} - -export { Form }; -export default withTranslation()(Form); +export default Form; diff --git a/src/components/Form/test.js b/src/components/Form/test.js index 6f480dd..ca64cb2 100644 --- a/src/components/Form/test.js +++ b/src/components/Form/test.js @@ -5,14 +5,13 @@ jest.mock('react-feather/dist/icons/chevrons-down', () => import React from 'react'; import { render, fireEvent } from 'react-testing-library'; -import { mockT } from 'i18n'; -import { Form } from 'components/Form'; +import Form from 'components/Form'; const syntaxList = [ { id: 'testJS', label: 'Testing JS' }, { id: 'other', label: 'Other' } ]; -const commonProps = { syntaxList, t: mockT }; +const commonProps = { syntaxList }; describe('Form', () => { test('rendering', () => {