@@ -2,7 +2,7 @@ import React from 'react';
22import { cleanup , fireEvent , render } from '@testing-library/react' ;
33import '@testing-library/jest-dom' ;
44import { MessageRepliesCountButton } from '../MessageRepliesCountButton' ;
5- import { TranslationProvider } from '../../../context' ;
5+ import { ChannelStateProvider , TranslationProvider } from '../../../context' ;
66
77const onClickMock = jest . fn ( ) ;
88const defaultSingularText = '1 reply' ;
@@ -11,10 +11,14 @@ const defaultPluralText = '2 replies';
1111const 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} ) ;
0 commit comments