@@ -122,12 +122,129 @@ describe('AttachmentSelector', () => {
122122 expect ( menu ) . toHaveTextContent ( 'Location' ) ;
123123 } ) ;
124124
125+ it ( 'renders with poll only if only polls are enabled' , async ( ) => {
126+ const {
127+ channels : [ customChannel ] ,
128+ client : customClient ,
129+ } = await initClientWithChannels ( {
130+ channelsData : [
131+ {
132+ channel : {
133+ ...defaultChannelData ,
134+ cid : 'type:id' ,
135+ config : {
136+ polls : true ,
137+ shared_locations : false ,
138+ uploads : false ,
139+ } ,
140+ id : 'id' ,
141+ type : 'type' ,
142+ } ,
143+ } ,
144+ ] ,
145+ } ) ;
146+ await renderComponent ( {
147+ channelStateContext : { channelCapabilities : { 'send-poll' : true } } ,
148+ customChannel,
149+ customClient,
150+ } ) ;
151+
152+ await invokeMenu ( ) ;
153+ const menu = screen . getByTestId ( ATTACHMENT_SELECTOR__ACTIONS_MENU_TEST_ID ) ;
154+ expect ( menu ) . toBeInTheDocument ( ) ;
155+ expect ( menu ) . not . toHaveTextContent ( 'File' ) ;
156+ expect ( menu ) . toHaveTextContent ( 'Poll' ) ;
157+ expect ( menu ) . not . toHaveTextContent ( 'Location' ) ;
158+ } ) ;
159+
160+ it ( 'does not render with poll only if polls are not enabled and send-poll permission is granted' , async ( ) => {
161+ const {
162+ channels : [ customChannel ] ,
163+ client : customClient ,
164+ } = await initClientWithChannels ( {
165+ channelsData : [
166+ {
167+ channel : {
168+ ...defaultChannelData ,
169+ cid : 'type:id' ,
170+ config : {
171+ polls : false ,
172+ shared_locations : false ,
173+ uploads : false ,
174+ } ,
175+ id : 'id' ,
176+ type : 'type' ,
177+ } ,
178+ } ,
179+ ] ,
180+ } ) ;
181+ await renderComponent ( {
182+ channelStateContext : { channelCapabilities : { 'send-poll' : true } } ,
183+ customChannel,
184+ customClient,
185+ } ) ;
186+
187+ expect (
188+ screen . queryByTestId ( 'invoke-attachment-selector-button' ) ,
189+ ) . not . toBeInTheDocument ( ) ;
190+ } ) ;
191+
192+ it ( 'renders with location only if only shared_locations are enabled' , async ( ) => {
193+ const {
194+ channels : [ customChannel ] ,
195+ client : customClient ,
196+ } = await initClientWithChannels ( {
197+ channelsData : [
198+ {
199+ channel : {
200+ ...defaultChannelData ,
201+ cid : 'type:id' ,
202+ config : {
203+ polls : false ,
204+ shared_locations : true ,
205+ uploads : false ,
206+ } ,
207+ id : 'id' ,
208+ type : 'type' ,
209+ } ,
210+ } ,
211+ ] ,
212+ } ) ;
213+ await renderComponent ( {
214+ channelStateContext : { channelCapabilities : { } } ,
215+ customChannel,
216+ customClient,
217+ } ) ;
218+
219+ await invokeMenu ( ) ;
220+ const menu = screen . getByTestId ( ATTACHMENT_SELECTOR__ACTIONS_MENU_TEST_ID ) ;
221+ expect ( menu ) . toBeInTheDocument ( ) ;
222+ expect ( menu ) . not . toHaveTextContent ( 'File' ) ;
223+ expect ( menu ) . not . toHaveTextContent ( 'Poll' ) ;
224+ expect ( menu ) . toHaveTextContent ( 'Location' ) ;
225+ } ) ;
226+
125227 it ( 'falls back to SimpleAttachmentSelector if only file uploads are enabled' , async ( ) => {
126228 const {
127229 channels : [ customChannel ] ,
128230 client : customClient ,
129- } = await initClientWithChannels ( ) ;
130- customChannel . messageComposer . updateConfig ( { location : { enabled : false } } ) ;
231+ } = await initClientWithChannels ( {
232+ channelsData : [
233+ {
234+ channel : {
235+ ...defaultChannelData ,
236+ cid : 'type:id' ,
237+ config : {
238+ polls : false ,
239+ shared_locations : false ,
240+ uploads : true ,
241+ } ,
242+ id : 'id' ,
243+ type : 'type' ,
244+ } ,
245+ } ,
246+ ] ,
247+ } ) ;
131248 const { container } = await renderComponent ( {
132249 channelStateContext : { channelCapabilities : { 'upload-file' : true } } ,
133250 customChannel,
@@ -139,27 +256,67 @@ describe('AttachmentSelector', () => {
139256 expect ( screen . getByTestId ( 'file-upload-button' ) ) . toBeInTheDocument ( ) ;
140257 } ) ;
141258
259+ it ( 'does not render SimpleAttachmentSelector neither AttachmentSelector menu if upload permission is granted but file upload disabled' , async ( ) => {
260+ const {
261+ channels : [ customChannel ] ,
262+ client : customClient ,
263+ } = await initClientWithChannels ( {
264+ channelsData : [
265+ {
266+ channel : {
267+ ...defaultChannelData ,
268+ cid : 'type:id' ,
269+ config : {
270+ polls : false ,
271+ shared_locations : false ,
272+ uploads : false ,
273+ } ,
274+ id : 'id' ,
275+ type : 'type' ,
276+ } ,
277+ } ,
278+ ] ,
279+ } ) ;
280+ await renderComponent ( {
281+ channelStateContext : { channelCapabilities : { 'upload-file' : true } } ,
282+ customChannel,
283+ customClient,
284+ } ) ;
285+
286+ expect (
287+ screen . queryByTestId ( 'invoke-attachment-selector-button' ) ,
288+ ) . not . toBeInTheDocument ( ) ;
289+ expect ( screen . queryByTestId ( 'file-upload-button' ) ) . not . toBeInTheDocument ( ) ;
290+ } ) ;
291+
142292 it ( 'renders SimpleAttachmentSelector if rendered in a thread' , async ( ) => {
143293 const {
144- channels : [ channel ] ,
145- client,
294+ channels : [ customChannel ] ,
295+ client : customClient ,
146296 } = await initClientWithChannels ( {
147297 channelsData : [
148298 {
149299 channel : {
150300 ...defaultChannelData ,
151301 cid : 'type:id' ,
152- config : defaultConfig ,
302+ config : {
303+ polls : false ,
304+ shared_locations : false ,
305+ uploads : true ,
306+ } ,
153307 id : 'id' ,
154308 type : 'type' ,
155309 } ,
156310 } ,
157311 ] ,
158312 } ) ;
159313 const { container } = await renderComponent ( {
160- channel,
161- channelStateContext : { thread : generateMessage ( { cid : channel . cid } ) } ,
162- client,
314+ channelStateContext : {
315+ channelCapabilities : { 'upload-file' : true } ,
316+ thread : generateMessage ( { cid : customChannel . cid } ) ,
317+ } ,
318+ customChannel,
319+ customClient,
163320 } ) ;
164321 expect (
165322 container . querySelector ( `.${ ATTACHMENT_SELECTOR_CLASS } ` ) ,
0 commit comments