diff --git a/src/modules/ChannelSettings/__test__/ChannelSettings.spec.tsx b/src/modules/ChannelSettings/__test__/ChannelSettings.spec.tsx new file mode 100644 index 000000000..d98d5dff5 --- /dev/null +++ b/src/modules/ChannelSettings/__test__/ChannelSettings.spec.tsx @@ -0,0 +1,145 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; +import { ChannelSettingsProvider } from '../context'; +import ChannelProfile from '../components/ChannelProfile'; +import ChannelSettingsUI from '../components/ChannelSettingsUI'; +import ChannelSettingsHeader from '../components/ChannelSettingsUI/ChannelSettingsHeader'; +import MenuItem from '../components/ChannelSettingsUI/MenuItem'; +import EditDetailsModal from '../components/EditDetailsModal'; +import LeaveChannel from '../components/LeaveChannel'; +import UserListItem from '../components/UserListItem'; +import { User } from '@sendbird/chat'; +import UserPanel from '../components/UserPanel'; +import ModerationPanel from '../components/ModerationPanel'; + +// Mock createPortal function to render content directly without portal +jest.mock('react-dom', () => ({ + ...jest.requireActual('react-dom'), + createPortal: (node) => node, +})); + +describe('ChannelSettings Unit Tests', () => { + const defaultProps = { + channelUrl: 'mockChannelUrl', + }; + + it('renders ChannelSettingsUI with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ChannelProfile with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ChannelSettingsHeader with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ChannelSettingMenuList with default value', () => { + expect(() => { + render( + + + null} + renderMiddle={() => null} + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders EditDetailsModal with default value', () => { + expect(() => { + render( + + + jest.fn()} + onCancel={() => jest.fn()} + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders LeaveChannel with default value', () => { + expect(() => { + render( + + + jest.fn()} + onCancel={() => jest.fn()} + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders UserLisItem with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders UserPanel with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ModerationPanel with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + +}); diff --git a/src/modules/CreateChannel/__test__/CreateChannel.spec.tsx b/src/modules/CreateChannel/__test__/CreateChannel.spec.tsx new file mode 100644 index 000000000..9d6174c4c --- /dev/null +++ b/src/modules/CreateChannel/__test__/CreateChannel.spec.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; +import { CreateChannelProvider } from '../context'; +import CreateChannelUI from '../components/CreateChannelUI'; +import InviteUsers from '../components/InviteUsers'; +import SelectChannelType from '../components/SelectChannelType'; + +// Mock createPortal function to render content directly without portal +jest.mock('react-dom', () => ({ + ...jest.requireActual('react-dom'), + createPortal: (node) => node, +})); + +jest.mock('../components/InviteUsers/utils', () => ({ + ...jest.requireActual('../components/InviteUsers/utils'), + createDefaultUserListQuery: () => ({ + isLoading: false, + next: async () => [], + }), +})); + +describe('CreateChannel Unit Tests', () => { + const defaultProps = { + onChannelCreated: () => jest.fn(), + }; + + it('renders CreateChannelUI with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders InviteUsers with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders SelectChannelType with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + +}); diff --git a/src/modules/GroupChannel/__test__/GroupChannel.spec.tsx b/src/modules/GroupChannel/__test__/GroupChannel.spec.tsx new file mode 100644 index 000000000..800eb5600 --- /dev/null +++ b/src/modules/GroupChannel/__test__/GroupChannel.spec.tsx @@ -0,0 +1,201 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import MessageList from '../components/MessageList'; +import { GroupChannelProvider } from '../context'; +import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; +import GroupChannelHeader from '../components/GroupChannelHeader'; +import GroupChannelUI from '../components/GroupChannelUI'; +import FileViewer from '../components/FileViewer'; +import { FileMessage } from '@sendbird/chat/message'; +import FrozenNotification from '../components/FrozenNotification'; +import Message from '../components/Message'; +import { EveryMessage } from '../../../types'; +import RemoveMessageModal from '../components/RemoveMessageModal'; +import TypingIndicator from '../components/TypingIndicator'; +import UnreadCount from '../components/UnreadCount'; +import SuggestedMentionList from '../components/SuggestedMentionList'; +import SuggestedReplies from '../components/SuggestedReplies'; + +// Mock createPortal function to render content directly without portal +jest.mock('react-dom', () => ({ + ...jest.requireActual('react-dom'), + createPortal: (node) => node, +})); + +describe('GroupChannel Unit Tests', () => { + const defaultProps = { + channelUrl: 'test-channel', + }; + + it('renders GroupChannelUI with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders GroupChannelHeader with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders FileViewer with default value', () => { + expect(() => { + render( + + + jest.fn()} + message={ + { + sender: { role: 'none' }, + messageParams: { + message: 'mockTestMessage', + }, + } as FileMessage + } + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders FrozenNotification with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders Message with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders MessageList with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders RemoveMessageModal with default value', () => { + expect(() => { + render( + + + jest.fn()} + message={ + { + sender: { role: 'none' }, + messageParams: { + message: 'mockTestMessage', + }, + } as any + } + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders TypingIndicator with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders UnreadCount with default value', () => { + expect(() => { + render( + + + jest.fn()}/> + , + , + ); + }).not.toThrow(); + }); + + it('renders SuggestedMentionsList with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders SuggestedMentionsList with default value', () => { + expect(() => { + render( + + + jest.fn()} + /> + , + , + ); + }).not.toThrow(); + }); + +}); diff --git a/src/modules/GroupChannel/__test__/MessageList.integration.test.tsx b/src/modules/GroupChannel/__test__/MessageList.integration.test.tsx deleted file mode 100644 index 85ef00d2a..000000000 --- a/src/modules/GroupChannel/__test__/MessageList.integration.test.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import '@testing-library/jest-dom/extend-expect'; -import MessageList from '../components/MessageList'; -import { GroupChannelProvider } from '../context'; -import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; - -describe('MessageList Unit Tests', () => { - const defaultProps = { - channelUrl: 'test-channel', - }; - - it('renders MessageList with default value', () => { - render( - - - - , - , - ); - }); -}); diff --git a/src/modules/GroupChannel/components/Message/index.tsx b/src/modules/GroupChannel/components/Message/index.tsx index f86a91f9a..749bb5716 100644 --- a/src/modules/GroupChannel/components/Message/index.tsx +++ b/src/modules/GroupChannel/components/Message/index.tsx @@ -51,10 +51,10 @@ export const Message = (props: MessageProps): React.ReactElement => { // Use `allMessages[allMessages.length - 1]` instead of `currentGroupChannel.lastMessage` // because lastMessage is not updated when **Bot** sends messages const lastMessageInView = messages[messages.length - 1]; - const hasUnsentMessage = isSendableMessage(lastMessageInView) && lastMessageInView.sendingStatus !== 'succeeded'; + const hasUnsentMessage = isSendableMessage(lastMessageInView) && lastMessageInView?.sendingStatus !== 'succeeded'; const showSuggestedReplies = showSuggestedRepliesFor === 'all_messages' ? true - : message.messageId === lastMessageInView.messageId; + : message.messageId === lastMessageInView?.messageId; return enableSuggestedReplies && getSuggestedReplies(message).length > 0 && !hasUnsentMessage && showSuggestedReplies; }); @@ -62,7 +62,7 @@ export const Message = (props: MessageProps): React.ReactElement => { { const { result } = renderHook(() => useGroupChannel(), { wrapper }); act(() => { - result.current.actions.setCurrentChannel(mockChannel as GroupChannel); + result.current.actions.setCurrentChannel(mockChannel as unknown as GroupChannel); }); expect(result.current.state.currentChannel).toEqual(mockChannel); diff --git a/src/modules/GroupChannelList/__test__/GroupChannelList.spec.tsx b/src/modules/GroupChannelList/__test__/GroupChannelList.spec.tsx new file mode 100644 index 000000000..134af89a8 --- /dev/null +++ b/src/modules/GroupChannelList/__test__/GroupChannelList.spec.tsx @@ -0,0 +1,90 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; +import AddGroupChannel from '../components/AddGroupChannel'; +import { GroupChannelListProvider } from '../context'; +import GroupChannelListUI from '../components/GroupChannelListUI'; +import GroupChannelListHeader from '../components/GroupChannelListHeader'; +import { GroupChannelListItem } from '../components/GroupChannelListItem'; +import { GroupChannel } from '@sendbird/chat/groupChannel'; +import GroupChannelPreviewAction from '../components/GroupChannelPreviewAction'; + +describe('GroupChannelList Unit Tests', () => { + const defaultProps = { + onChannelSelect: () => jest.fn(), + onChannelCreated: () => jest.fn(), + }; + + it('renders GroupChannelListUI with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders AddGroupChannel with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders GroupChannelListHeader with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders GroupChannelListItem with default value', () => { + expect(() => { + render( + + + jest.fn()} + renderChannelAction={() => null} + /> + , + , + ); + }).not.toThrow(); + }); + + it('renders GroupChannelPreviewAction with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + +}); diff --git a/src/modules/Thread/__test__/Thread.spec.tsx b/src/modules/Thread/__test__/Thread.spec.tsx new file mode 100644 index 000000000..ea675a8a9 --- /dev/null +++ b/src/modules/Thread/__test__/Thread.spec.tsx @@ -0,0 +1,101 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import SendbirdProvider from '../../../lib/Sendbird/context/SendbirdProvider'; +import { ThreadProvider } from '../context'; +import { SendableMessageType } from '../../../utils'; +import ThreadUI from '../components/ThreadUI'; +import ThreadHeader from '../components/ThreadHeader'; +import ParentMessageInfoItem from '../components/ParentMessageInfo/ParentMessageInfoItem'; +import ThreadList from '../components/ThreadList'; +import ThreadListItem from '../components/ThreadList/ThreadListItem'; +import ThreadMessageInput from '../components/ThreadMessageInput'; + +describe('Thread Unit Tests', () => { + const defaultProps = { + channelUrl: 'test-channel', + message: { + messageId: 'test-message-id', + } as unknown as SendableMessageType, + parentMessage: { + messageId: 'test-parent-message-id', + }, + }; + + it('renders ThreadUI with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ThreadHeader with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ParentMessageInfo with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ThreadList with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ThreadListItem with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + + it('renders ThreadMessageInput with default value', () => { + expect(() => { + render( + + + + , + , + ); + }).not.toThrow(); + }); + +});