This file contains hidden or 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
| import React, { Component } from 'react'; | |
| import { | |
| View, | |
| } from 'react-native'; | |
| export default class NewMessageForm extends Component { | |
| render() { | |
| return ( | |
| <View> | |
| </View> |
This file contains hidden or 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
| import React, { Component } from 'react'; | |
| import { | |
| + TextInput, | |
| View, | |
| } from 'react-native'; | |
| export default class NewMessageForm extends Component { | |
| render() { | |
| return ( | |
| <View> |
This file contains hidden or 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
| import React, { Component } from 'react'; | |
| import { | |
| + Button, | |
| TextInput, | |
| View, | |
| } from 'react-native'; | |
| ... | |
| <TextInput | |
| testID="messageText" | |
| /> |
This file contains hidden or 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
| import React from 'react'; | |
| import { render, fireEvent } from 'react-native-testing-library'; | |
| import NewMessageForm from '../../NewMessageForm'; | |
| describe('NewMessageForm', () => { | |
| describe('clicking send', () => { | |
| const messageText = 'Hello world'; | |
| let getByTestId; |
This file contains hidden or 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
| export default class NewMessageForm extends Component { | |
| + state = { inputText: '' } | |
| + | |
| + handleChangeText = (text) => { | |
| + this.setState({ inputText: text }); | |
| + } | |
| + | |
| render() { | |
| + const { inputText } = this.state; | |
| return ( |
This file contains hidden or 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
| export default class NewMessageForm extends Component { | |
| state = { inputText: '' } | |
| handleChangeText = (text) => { | |
| this.setState({ inputText: text }); | |
| } | |
| + handleSend = () => { | |
| + this.setState({ inputText: '' }); | |
| + } |
This file contains hidden or 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
| describe('clicking send', () => { | |
| const messageText = 'Hello world'; | |
| + let sendHandler; | |
| let getByTestId; | |
| beforeEach(() => { | |
| + sendHandler = jest.fn(); | |
| - ({ getByTestId } = render(<NewMessageForm />)); |
This file contains hidden or 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
| handleSend = () => { | |
| + const { inputText } = this.state; | |
| + const { onSend } = this.props; | |
| + | |
| + onSend(inputText); | |
| + | |
| this.setState({ inputText: '' }); | |
| } |
This file contains hidden or 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
| export default class App extends Component { | |
| + handleSend = (newMessage) => { | |
| + } | |
| + | |
| render() { | |
| return ( | |
| <View> | |
| - <NewMessageForm /> | |
| + <NewMessageForm onSend={this.handleSend} /> | |
| </View> |
This file contains hidden or 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
| export default class App extends Component { | |
| + state = { messages: [] } | |
| + | |
| handleSend = (newMessage) => { | |
| + this.setState(state => ({ messages: [newMessage, ...state.messages] })); | |
| } |