Add Input-test.js

This commit is contained in:
Jerko Steiner 2017-06-17 10:56:05 -04:00
parent 06821e1fce
commit 4009b9c7d7
2 changed files with 62 additions and 1 deletions

View File

@ -38,7 +38,7 @@ export default class Input extends React.Component {
<form className="input" onSubmit={this.handleSubmit}>
<input
onChange={this.handleChange}
onKeyPress={this.onKeyPress}
onKeyPress={this.handleKeyPress}
placeholder="Enter your message..."
type="text"
value={message}

View File

@ -0,0 +1,61 @@
jest.mock('../../callId.js')
jest.mock('../../iceServers.js')
jest.mock('../../peer/peers.js')
import Input from '../Input.js'
import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-dom/test-utils'
import peers from '../../peer/peers.js'
describe('components/Input', () => {
let component, node, notify
function render () {
notify = jest.fn()
component = TestUtils.renderIntoDocument(
<Input
notify={notify}
/>
)
node = ReactDOM.findDOMNode(component)
}
let message = 'test message'
beforeEach(() => render())
describe('send message', () => {
let input
beforeEach(() => {
peers.message.mockClear()
input = node.querySelector('input')
TestUtils.Simulate.change(input, {
target: { value: message }
})
expect(input.value).toBe(message)
})
describe('handleSubmit', () => {
it('sends a message', () => {
TestUtils.Simulate.submit(node)
expect(input.value).toBe('')
expect(peers.message.mock.calls).toEqual([[ message ]])
expect(notify.mock.calls).toEqual([[ `You: ${message}` ]])
})
})
describe('handleKeyPress', () => {
it('sends a message', () => {
TestUtils.Simulate.keyPress(input, {
key: 'Enter'
})
expect(input.value).toBe('')
expect(peers.message.mock.calls).toEqual([[ message ]])
expect(notify.mock.calls).toEqual([[ `You: ${message}` ]])
})
})
})
})