Add Input-test.js
This commit is contained in:
parent
06821e1fce
commit
4009b9c7d7
@ -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}
|
||||
|
||||
61
src/client/components/__tests__/Input-test.js
Normal file
61
src/client/components/__tests__/Input-test.js
Normal 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}` ]])
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user