Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed May 29, 2024
2 parents bffcf77 + aaef483 commit 7919438
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [11.19.0](https://github.com/GetStream/stream-chat-react/compare/v11.18.1...v11.19.0) (2024-05-23)


### Bug Fixes

* fix aria label translations for Portuguese ([28b6dfd](https://github.com/GetStream/stream-chat-react/commit/28b6dfdd028ce1b53707d4fba8495b5722900c75))
* 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))
* 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))


### Features

* adopt new queryReactions endpoint ([#2388](https://github.com/GetStream/stream-chat-react/issues/2388)) ([d6ca4ef](https://github.com/GetStream/stream-chat-react/commit/d6ca4effd48272921407100b5c75dfc9dc1961d4))

## [11.18.1](https://github.com/GetStream/stream-chat-react/compare/v11.18.0...v11.18.1) (2024-05-10)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const useGiphyPreview = <

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

return { giphyPreviewMessage, setGiphyPreviewMessage };
return {
giphyPreviewMessage,
setGiphyPreviewMessage: separateGiphyPreview ? setGiphyPreviewMessage : undefined,
};
};
92 changes: 92 additions & 0 deletions src/components/MessageList/hooks/__tests__/useGiphyPreview.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React from 'react';
import { act } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import {
dispatchMessageNewEvent,
generateMessage,
generateUser,
getTestClientWithUser,
} from '../../../../mock-builders';

import { useGiphyPreview } from '../VirtualizedMessageList';
import { ChatProvider } from '../../../../context';

const me = generateUser();
const otherUser = generateUser();

const ownGiphyMessage = generateMessage({ command: 'giphy', user: me });
const foreignGiphyMessage = generateMessage({ command: 'giphy', user: otherUser });
const ownNonGiphyMessage = generateMessage({ user: me });
const foreignNonGiphyMessage = generateMessage({ user: otherUser });

const render = ({ client, separateGiphyPreview }) => {
const wrapper = ({ children }) => <ChatProvider value={{ client }}>{children}</ChatProvider>;
return renderHook(() => useGiphyPreview(separateGiphyPreview), { wrapper });
};
describe('useGiphyPreview', () => {
it('does not expose setGiphyPreviewMessage function if separateGiphyPreview is disabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: false });
expect(result.current.giphyPreviewMessage).toBeUndefined();
expect(result.current.setGiphyPreviewMessage).toBeUndefined();
});

it('exposes setGiphyPreviewMessage function if separateGiphyPreview is enabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: true });
expect(result.current.giphyPreviewMessage).toBeUndefined();
expect(result.current.setGiphyPreviewMessage).toStrictEqual(expect.any(Function));
});

it('unsets giphy preview with new own giphy message when separateGiphyPreview is enabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: true });
await act(() => {
result.current.setGiphyPreviewMessage(ownGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
await act(() => {
dispatchMessageNewEvent(client, ownGiphyMessage);
});
expect(result.current.giphyPreviewMessage).toBeUndefined();
});

it('does not unset giphy preview with new foreign giphy message when separateGiphyPreview is enabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: true });
await act(() => {
result.current.setGiphyPreviewMessage(ownGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
await act(() => {
dispatchMessageNewEvent(client, foreignGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
});

it('does not unset giphy preview with new own non-giphy message when separateGiphyPreview is enabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: true });
await act(() => {
result.current.setGiphyPreviewMessage(ownGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
await act(() => {
dispatchMessageNewEvent(client, ownNonGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
});

it('does not unset giphy preview with new foreign non-giphy message when separateGiphyPreview is enabled', async () => {
const client = await getTestClientWithUser(me);
const { result } = render({ client, separateGiphyPreview: true });
await act(() => {
result.current.setGiphyPreviewMessage(ownGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
await act(() => {
dispatchMessageNewEvent(client, foreignNonGiphyMessage);
});
expect(result.current.giphyPreviewMessage.id).toBe(ownGiphyMessage.id);
});
});

0 comments on commit 7919438

Please sign in to comment.