@@ -52,7 +52,7 @@ const renderComponent = async (
5252 messageInputContextOverrides = { } ,
5353 activeChannel = channel ,
5454) => {
55- const placeholderText = props . placeholder || 'placeholder' ;
55+ const placeholderText = props . placeholder === null ? null : props . placeholder || 'placeholder' ;
5656
5757 const OverrideMessageInputContext = ( { children } ) => {
5858 const currentContext = useMessageInputContext ( ) ;
@@ -70,24 +70,32 @@ const renderComponent = async (
7070 < ChatAutoComplete { ...props } placeholder = { placeholderText } />
7171 </ OverrideMessageInputContext >
7272 ) ;
73+ let renderResult ;
74+ await act ( ( ) => {
75+ renderResult = render (
76+ < Chat client = { chatClient } >
77+ < ActiveChannelSetter activeChannel = { activeChannel } />
78+ < Channel >
79+ < MessageInput emojiSearchIndex = { searchIndexMock } Input = { AutoComplete } />
80+ </ Channel >
81+ </ Chat > ,
82+ ) ;
83+ } ) ;
7384
74- const renderResult = render (
75- < Chat client = { chatClient } >
76- < ActiveChannelSetter activeChannel = { activeChannel } />
77- < Channel >
78- < MessageInput emojiSearchIndex = { searchIndexMock } Input = { AutoComplete } />
79- </ Channel >
80- </ Chat > ,
81- ) ;
82- const textarea = await waitFor ( ( ) => renderResult . getByPlaceholderText ( placeholderText ) ) ;
83- const typeText = ( text ) => {
84- fireEvent . change ( textarea , {
85- target : {
86- selectionEnd : text . length ,
87- value : text ,
88- } ,
89- } ) ;
90- } ;
85+ let textarea ;
86+ let typeText ;
87+ if ( placeholderText !== null ) {
88+ textarea = await waitFor ( ( ) => renderResult . getByPlaceholderText ( placeholderText ) ) ;
89+
90+ typeText = ( text ) => {
91+ fireEvent . change ( textarea , {
92+ target : {
93+ selectionEnd : text . length ,
94+ value : text ,
95+ } ,
96+ } ) ;
97+ } ;
98+ }
9199 return { ...renderResult , textarea, typeText } ;
92100} ;
93101
@@ -132,6 +140,20 @@ describe('ChatAutoComplete', () => {
132140 expect ( textarea ) . toBeDisabled ( ) ;
133141 } ) ;
134142
143+ it ( 'should give preference to prop disabled over the MessageInputContext value' , async ( ) => {
144+ const { textarea } = await renderComponent ( { disabled : false } , { disabled : true } ) ;
145+
146+ expect ( textarea ) . toBeEnabled ( ) ;
147+ } ) ;
148+
149+ it ( 'should give preference to cooldown value over the prop disabled' , async ( ) => {
150+ await renderComponent ( { disabled : false , placeholder : null } , { cooldownRemaining : 10 } ) ;
151+ expect ( screen . queryByPlaceholderText ( 'Placeholder' ) ) . not . toBeInTheDocument ( ) ;
152+ const textarea = screen . getByTestId ( 'message-input' ) ;
153+ expect ( textarea ) . toBeDisabled ( ) ;
154+ expect ( textarea ) . toHaveProperty ( 'placeholder' , 'Slow Mode ON' ) ;
155+ } ) ;
156+
135157 it ( 'should let you select emojis when you type :<emoji>' , async ( ) => {
136158 const emojiAutocompleteText = ':smile' ;
137159 const { findByText, textarea, typeText } = await renderComponent ( ) ;
0 commit comments