Skip to content

Commit

Permalink
reorganized imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TSlashDreamy committed Sep 5, 2023
1 parent 5e580d6 commit bc18163
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/containers/chat/chat-item/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'
import Badge from '@mui/material/Badge'

import { useChatContext } from '~/context/chat-context'
import { useAppSelector } from '~/hooks/use-redux'

import { styles } from '~/containers/chat/chat-item/ChatItem.styles'
import { ChatResponse, ComponentEnum, OverlapEnum, PositionEnum } from '~/types'
import { getFormattedDate } from '~/utils/helper-functions'
import { useChatContext } from '~/context/chat-context'

interface ItemOfChatProps {
isActiveChat: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import Typography from '@mui/material/Typography'

import ChatDate from '~/containers/chat/chat-date/ChatDate'
import ChatTextArea from '~/containers/chat/chat-text-area/ChatTextArea'
import Message from '~/components/message/Message'
import { useChatContext } from '~/context/chat-context'
import useAxios from '~/hooks/use-axios'
import Message from '~/components/message/Message'
import UserProfileInfo from '~/components/user-profile-info/UserProfileInfo'
import Loader from '~/components/loader/Loader'
import { messageService } from '~/services/message-service'
import { useChatContext } from '~/context/chat-context'
import { getGroupedMessages } from '~/utils/helper-functions'

import { ChatInfo, MessageInterface } from '~/types'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const Chat = () => {
useEffect(() => {
if (currentChatId) {
listOfChats.forEach((chat: ChatResponse) => {
if (chat._id === currentChatId) setSelectedChat(chat)
if (chat._id === currentChatId) return setSelectedChat(chat)
})
}
}, [currentChatId, listOfChats])
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/containers/chat/chat-item/ChatItem.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { screen, fireEvent } from '@testing-library/react'
import { renderWithProviders } from '~tests/test-utils'
import ChatItem from '~/containers/chat/chat-item/ChatItem'

const mockChatContext = {
setCurrentChatId: vi.fn()
}

vi.mock('~/context/chat-context', () => ({
useChatContext: () => mockChatContext
}))

const user = {
_id: '644e6b1668cc37f543f2f37c',
firstName: 'Albus',
Expand Down Expand Up @@ -55,5 +63,6 @@ describe('ChatItem', () => {
fireEvent.click(message)

expect(setSelectedChat).toHaveBeenCalledWith(chat)
expect(mockChatContext.setCurrentChatId).toHaveBeenCalledWith(null)
})
})

0 comments on commit bc18163

Please sign in to comment.