refactor: get roomId from props
This commit is contained in:
parent
0d28df82c2
commit
254ebf2580
@ -5,7 +5,8 @@ import { MemoryRouter as Router, Route, Routes } from 'react-router-dom'
|
|||||||
|
|
||||||
import { Room } from './'
|
import { Room } from './'
|
||||||
|
|
||||||
const stubUserId = 'user-id'
|
const mockUserId = 'user-id'
|
||||||
|
const mockRoomId = 'room-123'
|
||||||
|
|
||||||
const mockGetUuid = jest.fn()
|
const mockGetUuid = jest.fn()
|
||||||
const mockMessagedSender = jest
|
const mockMessagedSender = jest
|
||||||
@ -46,7 +47,7 @@ describe('Room', () => {
|
|||||||
test('is available', () => {
|
test('is available', () => {
|
||||||
render(
|
render(
|
||||||
<RouteStub>
|
<RouteStub>
|
||||||
<Room userId={stubUserId} />
|
<Room userId={mockUserId} roomId={mockRoomId} />
|
||||||
</RouteStub>
|
</RouteStub>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -54,7 +55,7 @@ describe('Room', () => {
|
|||||||
test('send button is disabled', () => {
|
test('send button is disabled', () => {
|
||||||
render(
|
render(
|
||||||
<RouteStub>
|
<RouteStub>
|
||||||
<Room userId={stubUserId} />
|
<Room userId={mockUserId} roomId={mockRoomId} />
|
||||||
</RouteStub>
|
</RouteStub>
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ describe('Room', () => {
|
|||||||
test('inputting text enabled send button', () => {
|
test('inputting text enabled send button', () => {
|
||||||
render(
|
render(
|
||||||
<RouteStub>
|
<RouteStub>
|
||||||
<Room userId={stubUserId} />
|
<Room userId={mockUserId} roomId={mockRoomId} />
|
||||||
</RouteStub>
|
</RouteStub>
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ describe('Room', () => {
|
|||||||
test('sending a message clears the text input', async () => {
|
test('sending a message clears the text input', async () => {
|
||||||
render(
|
render(
|
||||||
<RouteStub>
|
<RouteStub>
|
||||||
<Room userId={stubUserId} />
|
<Room userId={mockUserId} roomId={mockRoomId} />
|
||||||
</RouteStub>
|
</RouteStub>
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,7 +99,8 @@ describe('Room', () => {
|
|||||||
<RouteStub>
|
<RouteStub>
|
||||||
<Room
|
<Room
|
||||||
getUuid={mockGetUuid.mockImplementation(() => 'abc123')}
|
getUuid={mockGetUuid.mockImplementation(() => 'abc123')}
|
||||||
userId={stubUserId}
|
userId={mockUserId}
|
||||||
|
roomId={mockRoomId}
|
||||||
/>
|
/>
|
||||||
</RouteStub>
|
</RouteStub>
|
||||||
)
|
)
|
||||||
@ -112,7 +114,7 @@ describe('Room', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(mockMessagedSender).toHaveBeenCalledWith({
|
expect(mockMessagedSender).toHaveBeenCalledWith({
|
||||||
authorId: stubUserId,
|
authorId: mockUserId,
|
||||||
text: 'hello',
|
text: 'hello',
|
||||||
timeSent: 100,
|
timeSent: 100,
|
||||||
id: 'abc123',
|
id: 'abc123',
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useParams } from 'react-router-dom'
|
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
import FormControl from '@mui/material/FormControl'
|
import FormControl from '@mui/material/FormControl'
|
||||||
@ -14,16 +13,16 @@ import { ChatTranscript } from 'components/ChatTranscript'
|
|||||||
export interface RoomProps {
|
export interface RoomProps {
|
||||||
appId?: string
|
appId?: string
|
||||||
getUuid?: typeof uuid
|
getUuid?: typeof uuid
|
||||||
|
roomId: string
|
||||||
userId: string
|
userId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Room({
|
export function Room({
|
||||||
userId,
|
|
||||||
appId = `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
|
appId = `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
|
||||||
getUuid = uuid,
|
getUuid = uuid,
|
||||||
|
roomId,
|
||||||
|
userId,
|
||||||
}: RoomProps) {
|
}: RoomProps) {
|
||||||
const { roomId = '' } = useParams()
|
|
||||||
|
|
||||||
const [isMessageSending, setIsMessageSending] = useState(false)
|
const [isMessageSending, setIsMessageSending] = useState(false)
|
||||||
const [textMessage, setTextMessage] = useState('')
|
const [textMessage, setTextMessage] = useState('')
|
||||||
const [messageLog, setMessageLog] = useState<
|
const [messageLog, setMessageLog] = useState<
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { Room } from 'components/Room'
|
import { Room } from 'components/Room'
|
||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
interface PublicRoomProps {
|
interface PublicRoomProps {
|
||||||
userId: string
|
userId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PublicRoom({ userId }: PublicRoomProps) {
|
export function PublicRoom({ userId }: PublicRoomProps) {
|
||||||
return <Room userId={userId} />
|
const { roomId = '' } = useParams()
|
||||||
|
return <Room userId={userId} roomId={roomId} />
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user