Skip to content

Commit 9e70560

Browse files
authored
fix: disable reply count button when missing send-reply permission (#2871)
1 parent 33c6678 commit 9e70560

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"@playwright/test": "^1.42.1",
182182
"@semantic-release/changelog": "^6.0.3",
183183
"@semantic-release/git": "^10.0.1",
184-
"@stream-io/stream-chat-css": "^5.15.0",
184+
"@stream-io/stream-chat-css": "^5.16.0",
185185
"@testing-library/dom": "^10.4.0",
186186
"@testing-library/jest-dom": "^6.6.3",
187187
"@testing-library/react": "^16.2.0",

src/components/Message/MessageRepliesCountButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MouseEventHandler } from 'react';
22
import React from 'react';
33
import { useTranslationContext } from '../../context/TranslationContext';
4+
import { useChannelStateContext } from '../../context';
45

56
export type MessageRepliesCountButtonProps = {
67
/* If supplied, adds custom text to the end of a multiple replies message */
@@ -15,6 +16,7 @@ export type MessageRepliesCountButtonProps = {
1516

1617
const UnMemoizedMessageRepliesCountButton = (props: MessageRepliesCountButtonProps) => {
1718
const { labelPlural, labelSingle, onClick, reply_count = 0 } = props;
19+
const { channelCapabilities } = useChannelStateContext();
1820

1921
const { t } = useTranslationContext('MessageRepliesCountButton');
2022

@@ -33,6 +35,7 @@ const UnMemoizedMessageRepliesCountButton = (props: MessageRepliesCountButtonPro
3335
<button
3436
className='str-chat__message-replies-count-button'
3537
data-testid='replies-count-button'
38+
disabled={!channelCapabilities['send-reply']}
3639
onClick={onClick}
3740
>
3841
{replyCountText}

src/components/Message/__tests__/MessageRepliesCountButton.test.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { cleanup, fireEvent, render } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import { MessageRepliesCountButton } from '../MessageRepliesCountButton';
5-
import { TranslationProvider } from '../../../context';
5+
import { ChannelStateProvider, TranslationProvider } from '../../../context';
66

77
const onClickMock = jest.fn();
88
const defaultSingularText = '1 reply';
@@ -11,10 +11,14 @@ const defaultPluralText = '2 replies';
1111
const i18nMock = (key, { count }) =>
1212
count > 1 ? defaultPluralText : defaultSingularText;
1313

14-
const renderComponent = (props) =>
14+
const renderComponent = (props, channelStateCtx) =>
1515
render(
1616
<TranslationProvider value={{ t: i18nMock }}>
17-
<MessageRepliesCountButton {...props} onClick={onClickMock} />
17+
<ChannelStateProvider
18+
value={{ channelCapabilities: { 'send-reply': true }, ...channelStateCtx }}
19+
>
20+
<MessageRepliesCountButton {...props} onClick={onClickMock} />
21+
</ChannelStateProvider>
1822
</TranslationProvider>,
1923
);
2024

@@ -26,8 +30,8 @@ describe('MessageRepliesCountButton', () => {
2630

2731
it('should render the right text when there is one reply, and labelSingle is not defined', () => {
2832
const { getByText } = renderComponent({ reply_count: 1 });
29-
30-
expect(getByText(defaultSingularText)).toBeInTheDocument();
33+
const button = getByText(defaultSingularText);
34+
expect(button).not.toBeDisabled();
3135
});
3236

3337
it('should render the right text when there is one reply, and labelSingle is defined', () => {
@@ -79,4 +83,13 @@ describe('MessageRepliesCountButton', () => {
7983
});
8084
expect(queryByTestId('reply-icon')).not.toBeInTheDocument();
8185
});
86+
87+
it('should be disabled on missing "send-reply" permission', () => {
88+
const { getByText } = renderComponent(
89+
{ reply_count: 1 },
90+
{ channelCapabilities: { 'send-reply': false } },
91+
);
92+
93+
expect(getByText(defaultSingularText)).toBeDisabled();
94+
});
8295
});

src/components/Message/__tests__/MessageSimple.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('<MessageSimple />', () => {
8181
let client;
8282

8383
async function renderMessageSimple({
84-
channelCapabilities = { 'send-reaction': true },
84+
channelCapabilities = { 'send-reaction': true, 'send-reply': true },
8585
channelConfigOverrides = { replies: true },
8686
components = {},
8787
message,

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,10 +2601,10 @@
26012601
resolved "https://registry.yarnpkg.com/@stream-io/escape-string-regexp/-/escape-string-regexp-5.0.1.tgz#362505c92799fea6afe4e369993fbbda8690cc37"
26022602
integrity sha512-qIaSrzJXieZqo2fZSYTdzwSbZgHHsT3tkd646vvZhh4fr+9nO4NlvqGmPF43Y+OfZiWf+zYDFgNiPGG5+iZulQ==
26032603

2604-
"@stream-io/stream-chat-css@^5.15.0":
2605-
version "5.15.0"
2606-
resolved "https://registry.yarnpkg.com/@stream-io/stream-chat-css/-/stream-chat-css-5.15.0.tgz#3e9ef12eb3f6390c16dfeff3e5192691bc3cc7e6"
2607-
integrity sha512-FlbEfT4S+gV/k4kivVL/7hHw0O5buqlN7FREL/NCv9tyYfaULKh9dYlzuuNR40bcq3cZVqg7fogY2zOrYbirzg==
2604+
"@stream-io/stream-chat-css@^5.16.0":
2605+
version "5.16.0"
2606+
resolved "https://registry.yarnpkg.com/@stream-io/stream-chat-css/-/stream-chat-css-5.16.0.tgz#e7e7af18ea072f686123880ed70b4497eb13f16c"
2607+
integrity sha512-Jpp94Nfxey9fcpFrhozGs09dAWMAUkZWdiORlByl76KDdgDZzZAyapdym9e7D/U3ZwQsR+/1P1W/P73UPrvkng==
26082608

26092609
"@stream-io/transliterate@^1.5.5":
26102610
version "1.5.5"

0 commit comments

Comments
 (0)