Skip to content

Commit 7919438

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents bffcf77 + aaef483 commit 7919438

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [11.19.0](https://github.com/GetStream/stream-chat-react/compare/v11.18.1...v11.19.0) (2024-05-23)
2+
3+
4+
### Bug Fixes
5+
6+
* fix aria label translations for Portuguese ([28b6dfd](https://github.com/GetStream/stream-chat-react/commit/28b6dfdd028ce1b53707d4fba8495b5722900c75))
7+
* prevent loading more non-existent thread replies ([#2399](https://github.com/GetStream/stream-chat-react/issues/2399)) ([f2ed479](https://github.com/GetStream/stream-chat-react/commit/f2ed47938d9a042d041198690ac65a3b3f0a934a))
8+
* prevent showing link previews in AttachmentPreviewList ([#2398](https://github.com/GetStream/stream-chat-react/issues/2398)) ([cf24894](https://github.com/GetStream/stream-chat-react/commit/cf24894f1743ebfb831dcdc2c802164f5807a9a6))
9+
10+
11+
### Features
12+
13+
* adopt new queryReactions endpoint ([#2388](https://github.com/GetStream/stream-chat-react/issues/2388)) ([d6ca4ef](https://github.com/GetStream/stream-chat-react/commit/d6ca4effd48272921407100b5c75dfc9dc1961d4))
14+
115
## [11.18.1](https://github.com/GetStream/stream-chat-react/compare/v11.18.0...v11.18.1) (2024-05-10)
216

317

src/components/MessageList/hooks/VirtualizedMessageList/useGiphyPreview.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export const useGiphyPreview = <
3030

3131
if (separateGiphyPreview) client.on('message.new', handleEvent);
3232
return () => client.off('message.new', handleEvent);
33-
// eslint-disable-next-line react-hooks/exhaustive-deps
34-
}, [separateGiphyPreview]);
33+
}, [client, separateGiphyPreview]);
3534

36-
return { giphyPreviewMessage, setGiphyPreviewMessage };
35+
return {
36+
giphyPreviewMessage,
37+
setGiphyPreviewMessage: separateGiphyPreview ? setGiphyPreviewMessage : undefined,
38+
};
3739
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React from 'react';
2+
import { act } from '@testing-library/react';
3+
import { renderHook } from '@testing-library/react-hooks';
4+
import {
5+
dispatchMessageNewEvent,
6+
generateMessage,
7+
generateUser,
8+
getTestClientWithUser,
9+
} from '../../../../mock-builders';
10+
11+
import { useGiphyPreview } from '../VirtualizedMessageList';
12+
import { ChatProvider } from '../../../../context';
13+
14+
const me = generateUser();
15+
const otherUser = generateUser();
16+
17+
const ownGiphyMessage = generateMessage({ command: 'giphy', user: me });
18+
const foreignGiphyMessage = generateMessage({ command: 'giphy', user: otherUser });
19+
const ownNonGiphyMessage = generateMessage({ user: me });
20+
const foreignNonGiphyMessage = generateMessage({ user: otherUser });
21+
22+
const render = ({ client, separateGiphyPreview }) => {
23+
const wrapper = ({ children }) => <ChatProvider value={{ client }}>{children}</ChatProvider>;
24+
return renderHook(() => useGiphyPreview(separateGiphyPreview), { wrapper });
25+
};
26+
describe('useGiphyPreview', () => {
27+
it('does not expose setGiphyPreviewMessage function if separateGiphyPreview is disabled', async () => {
28+
const client = await getTestClientWithUser(me);
29+
const { result } = render({ client, separateGiphyPreview: false });
30+
expect(result.current.giphyPreviewMessage).toBeUndefined();
31+
expect(result.current.setGiphyPreviewMessage).toBeUndefined();
32+
});
33+
34+
it('exposes setGiphyPreviewMessage function if separateGiphyPreview is enabled', async () => {
35+
const client = await getTestClientWithUser(me);
36+
const { result } = render({ client, separateGiphyPreview: true });
37+
expect(result.current.giphyPreviewMessage).toBeUndefined();
38+
expect(result.current.setGiphyPreviewMessage).toStrictEqual(expect.any(Function));
39+
});
40+
41+
it('unsets giphy preview with new own giphy message when separateGiphyPreview is enabled', async () => {
42+
const client = await getTestClientWithUser(me);
43+
const { result } = render({ client, separateGiphyPreview: true });
44+
await act(() => {
45+
result.current.setGiphyPreviewMessage(ownGiphyMessage);
46+
});
47+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
48+
await act(() => {
49+
dispatchMessageNewEvent(client, ownGiphyMessage);
50+
});
51+
expect(result.current.giphyPreviewMessage).toBeUndefined();
52+
});
53+
54+
it('does not unset giphy preview with new foreign giphy message when separateGiphyPreview is enabled', async () => {
55+
const client = await getTestClientWithUser(me);
56+
const { result } = render({ client, separateGiphyPreview: true });
57+
await act(() => {
58+
result.current.setGiphyPreviewMessage(ownGiphyMessage);
59+
});
60+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
61+
await act(() => {
62+
dispatchMessageNewEvent(client, foreignGiphyMessage);
63+
});
64+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
65+
});
66+
67+
it('does not unset giphy preview with new own non-giphy message when separateGiphyPreview is enabled', async () => {
68+
const client = await getTestClientWithUser(me);
69+
const { result } = render({ client, separateGiphyPreview: true });
70+
await act(() => {
71+
result.current.setGiphyPreviewMessage(ownGiphyMessage);
72+
});
73+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
74+
await act(() => {
75+
dispatchMessageNewEvent(client, ownNonGiphyMessage);
76+
});
77+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
78+
});
79+
80+
it('does not unset giphy preview with new foreign non-giphy message when separateGiphyPreview is enabled', async () => {
81+
const client = await getTestClientWithUser(me);
82+
const { result } = render({ client, separateGiphyPreview: true });
83+
await act(() => {
84+
result.current.setGiphyPreviewMessage(ownGiphyMessage);
85+
});
86+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
87+
await act(() => {
88+
dispatchMessageNewEvent(client, foreignNonGiphyMessage);
89+
});
90+
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
91+
});
92+
});

0 commit comments

Comments
 (0)