remnantchat/src/components/Room/Room.test.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-18 21:36:13 -05:00
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
2022-08-18 21:10:16 -05:00
import { MemoryRouter as Router, Route, Routes } from 'react-router-dom'
import { Room } from './'
const getRoomStub = () => {
return (
<Router initialEntries={['/public/abc123']}>
<Routes>
<Route path="/public/:roomId" element={<Room />}></Route>
</Routes>
</Router>
)
}
describe('Room', () => {
test('is available', () => {
render(getRoomStub())
})
2022-08-18 21:36:13 -05:00
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('')
})
2022-08-18 21:10:16 -05:00
})