test: validate message sending UX

This commit is contained in:
Jeremy Kahn 2022-08-18 21:36:13 -05:00
parent 6ffcd20429
commit 3bbe8b1430
2 changed files with 26 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { render } from '@testing-library/react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter as Router, Route, Routes } from 'react-router-dom'
import { Room } from './'
@ -17,4 +18,27 @@ describe('Room', () => {
test('is available', () => {
render(getRoomStub())
})
test('send button is disabled', () => {
render(getRoomStub())
const sendButton = screen.getByText('Send')
expect(sendButton).toBeDisabled()
})
test('inputting text enabled send button', () => {
render(getRoomStub())
const sendButton = screen.getByText('Send')
const textInput = screen.getByPlaceholderText('Your message')
userEvent.type(textInput, 'hello')
expect(sendButton).not.toBeDisabled()
})
test('sending a message clears the text input', () => {
render(getRoomStub())
const sendButton = screen.getByText('Send')
const textInput = screen.getByPlaceholderText('Your message')
userEvent.type(textInput, 'hello')
userEvent.click(sendButton)
expect(textInput).toHaveValue('')
})
})

View File

@ -62,11 +62,11 @@ export function Room({
<form onSubmit={handleMessageSubmit} className="max-w-xl mt-8">
<FormControl fullWidth>
<TextField
label="Your message"
variant="outlined"
value={textMessage}
onChange={handleMessageChange}
size="medium"
placeholder="Your message"
/>
</FormControl>
<Button