test: validate Room availability

This commit is contained in:
Jeremy Kahn 2022-08-18 21:10:16 -05:00
parent 85c4f24bd6
commit 6ffcd20429
3 changed files with 54 additions and 2 deletions

26
src/__mocks__/trystero.ts Normal file
View File

@ -0,0 +1,26 @@
import { joinRoom as trysteroJoinRoom, RoomConfig, Room } from 'trystero'
export const joinRoom: typeof trysteroJoinRoom = (
_config: RoomConfig,
_roomId: string
) => {
const room: Room = {
makeAction: () => [() => {}, () => {}, () => {}],
ping: () => Promise.resolve(0),
leave: () => {},
getPeers: () => [],
addStream: () => [Promise.resolve()],
removeStream: () => {},
addTrack: () => [Promise.resolve()],
removeTrack: () => {},
replaceTrack: () => [Promise.resolve()],
onPeerJoin: () => {},
onPeerLeave: () => {},
onPeerStream: () => {},
onPeerTrack: () => {},
}
return room
}
export const selfId = ''

View File

@ -0,0 +1,20 @@
import { render } from '@testing-library/react'
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())
})
})

View File

@ -9,7 +9,13 @@ import { usePeerRoom, usePeerRoomAction } from 'hooks/usePeerRoom'
import { PeerActions } from 'models/network'
import { UnsentMessage, ReceivedMessage } from 'models/chat'
export function Room() {
export interface RoomProps {
appId?: string
}
export function Room({
appId = `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
}: RoomProps) {
const { roomId = '' } = useParams()
const [textMessage, setTextMessage] = useState('')
@ -18,7 +24,7 @@ export function Room() {
)
const peerRoom = usePeerRoom({
appId: `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
appId,
roomId,
})