|
6 | 6 | generateUser, |
7 | 7 | initClientWithChannels, |
8 | 8 | } from '../../../mock-builders'; |
9 | | -import { act, fireEvent, render, screen } from '@testing-library/react'; |
| 9 | +import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; |
10 | 10 | import { ChatProvider, MessageProvider, useChannelActionContext } from '../../../context'; |
11 | 11 | import { Channel } from '../../Channel'; |
12 | 12 | import { MessageActionsBox } from '../../MessageActions'; |
@@ -78,7 +78,9 @@ const setup = async ({ channelData } = {}) => { |
78 | 78 | const sendFileSpy = jest.spyOn(customChannel, 'sendFile').mockResolvedValueOnce({ |
79 | 79 | file: fileUploadUrl, |
80 | 80 | }); |
81 | | - const getDraftSpy = jest.spyOn(customChannel, 'getDraft').mockResolvedValue({}); |
| 81 | + const getDraftSpy = jest |
| 82 | + .spyOn(customChannel, 'getDraft') |
| 83 | + .mockResolvedValue({ draft: { message: { id: 'x' } } }); |
82 | 84 | customChannel.initialized = true; |
83 | 85 | customClient.activeChannels[customChannel.cid] = customChannel; |
84 | 86 | return { customChannel, customClient, getDraftSpy, sendFileSpy, sendImageSpy }; |
@@ -157,47 +159,6 @@ const renderComponent = async ({ |
157 | 159 | }; |
158 | 160 |
|
159 | 161 | describe('MessageInput in Thread', () => { |
160 | | - it('renders in the thread context for direct messaging channel', async () => { |
161 | | - const { customChannel, customClient } = await setup(); |
162 | | - await renderComponent({ |
163 | | - customChannel, |
164 | | - customClient, |
165 | | - }); |
166 | | - expect(screen.getByLabelText('Also send as a direct message')).toBeInTheDocument(); |
167 | | - }); |
168 | | - it('renders in the thread context for non-direct messaging channel', async () => { |
169 | | - const mainListMessage = generateMessage({ cid, user }); |
170 | | - const threadMessage = generateMessage({ |
171 | | - parent_id: mainListMessage.id, |
172 | | - type: 'reply', |
173 | | - user, |
174 | | - }); |
175 | | - |
176 | | - const channelData = generateChannel({ |
177 | | - channel: { |
178 | | - id: 'general', |
179 | | - own_capabilities: ['send-poll', 'upload-file'], |
180 | | - type: 'messaging', |
181 | | - }, |
182 | | - members: [ |
183 | | - generateMember({ user }), |
184 | | - generateMember({ user: mentionUser }), |
185 | | - generateMember({ user: generateUser() }), |
186 | | - ], |
187 | | - // new parent message id has to be provided otherwise the cachedParentMessage in useMessageComposer |
188 | | - // will retrieve the composer from the previous test |
189 | | - messages: [{ ...mainListMessage, id: 'x' }], |
190 | | - thread: [{ ...threadMessage, parent_id: 'x' }], |
191 | | - }); |
192 | | - const { customChannel, customClient } = await setup({ channelData }); |
193 | | - await renderComponent({ |
194 | | - customChannel, |
195 | | - customClient, |
196 | | - thread: channelData.messages[0], |
197 | | - }); |
198 | | - expect(screen.getByLabelText('Also send in channel')).toBeInTheDocument(); |
199 | | - }); |
200 | | - |
201 | 162 | describe('draft', () => { |
202 | 163 | it('is queried when drafts are enabled', async () => { |
203 | 164 | const { customChannel, customClient, getDraftSpy } = await setup(); |
@@ -249,4 +210,48 @@ describe('MessageInput in Thread', () => { |
249 | 210 | expect(getDraftSpy).not.toHaveBeenCalled(); |
250 | 211 | }); |
251 | 212 | }); |
| 213 | + |
| 214 | + it('renders in the thread context for direct messaging channel', async () => { |
| 215 | + const { customChannel, customClient } = await setup(); |
| 216 | + await renderComponent({ |
| 217 | + customChannel, |
| 218 | + customClient, |
| 219 | + }); |
| 220 | + |
| 221 | + await waitFor(() => { |
| 222 | + expect(screen.getByLabelText('Also send as a direct message')).toBeInTheDocument(); |
| 223 | + }); |
| 224 | + }); |
| 225 | + it('renders in the thread context for non-direct messaging channel', async () => { |
| 226 | + const mainListMessage = generateMessage({ cid, user }); |
| 227 | + const threadMessage = generateMessage({ |
| 228 | + parent_id: mainListMessage.id, |
| 229 | + type: 'reply', |
| 230 | + user, |
| 231 | + }); |
| 232 | + |
| 233 | + const channelData = generateChannel({ |
| 234 | + channel: { |
| 235 | + id: 'general', |
| 236 | + own_capabilities: ['send-poll', 'upload-file'], |
| 237 | + type: 'messaging', |
| 238 | + }, |
| 239 | + members: [ |
| 240 | + generateMember({ user }), |
| 241 | + generateMember({ user: mentionUser }), |
| 242 | + generateMember({ user: generateUser() }), |
| 243 | + ], |
| 244 | + // new parent message id has to be provided otherwise the cachedParentMessage in useMessageComposer |
| 245 | + // will retrieve the composer from the previous test |
| 246 | + messages: [{ ...mainListMessage, id: 'x' }], |
| 247 | + thread: [{ ...threadMessage, parent_id: 'x' }], |
| 248 | + }); |
| 249 | + const { customChannel, customClient } = await setup({ channelData }); |
| 250 | + await renderComponent({ |
| 251 | + customChannel, |
| 252 | + customClient, |
| 253 | + thread: channelData.messages[0], |
| 254 | + }); |
| 255 | + expect(screen.getByLabelText('Also send in channel')).toBeInTheDocument(); |
| 256 | + }); |
252 | 257 | }); |
0 commit comments