1
1
/* eslint-disable jest-dom/prefer-to-have-class */
2
2
import React from 'react' ;
3
- import { fireEvent , render } from '@testing-library/react' ;
3
+ import { act , fireEvent , render , screen } from '@testing-library/react' ;
4
4
import '@testing-library/jest-dom' ;
5
5
6
6
import { Message } from '../Message' ;
@@ -22,6 +22,7 @@ import {
22
22
getTestClientWithUser ,
23
23
} from '../../../mock-builders' ;
24
24
import { DialogsManagerProvider } from '../../../context' ;
25
+ import { defaultReactionOptions } from '../../Reactions' ;
25
26
26
27
const MESSAGE_ACTIONS_TEST_ID = 'message-actions' ;
27
28
@@ -73,6 +74,7 @@ async function renderMessageOptions({
73
74
onReactionListClick = { customMessageProps ?. onReactionListClick }
74
75
/>
75
76
) ,
77
+ reactionOptions : defaultReactionOptions ,
76
78
} }
77
79
>
78
80
< Message { ...defaultMessageProps } { ...customMessageProps } >
@@ -182,6 +184,85 @@ describe('<MessageOptions />', () => {
182
184
expect ( queryByTestId ( reactionActionTestId ) ) . not . toBeInTheDocument ( ) ;
183
185
} ) ;
184
186
187
+ it ( 'should not render ReactionsSelector until open' , async ( ) => {
188
+ const { queryByTestId } = await renderMessageOptions ( {
189
+ channelStateOpts : {
190
+ channelCapabilities : { 'send-reaction' : true } ,
191
+ } ,
192
+ } ) ;
193
+ expect ( screen . queryByTestId ( 'reaction-selector' ) ) . not . toBeInTheDocument ( ) ;
194
+ await act ( async ( ) => {
195
+ await fireEvent . click ( queryByTestId ( reactionActionTestId ) ) ;
196
+ } ) ;
197
+ expect ( screen . getByTestId ( 'reaction-selector' ) ) . toBeInTheDocument ( ) ;
198
+ } ) ;
199
+
200
+ it ( 'should unmount ReactionsSelector when closed by click on dialog overlay' , async ( ) => {
201
+ const { queryByTestId } = await renderMessageOptions ( {
202
+ channelStateOpts : {
203
+ channelCapabilities : { 'send-reaction' : true } ,
204
+ } ,
205
+ } ) ;
206
+ await act ( async ( ) => {
207
+ await fireEvent . click ( queryByTestId ( reactionActionTestId ) ) ;
208
+ } ) ;
209
+ await act ( async ( ) => {
210
+ await fireEvent . click ( screen . getByTestId ( 'str-chat__dialog-overlay' ) ) ;
211
+ } ) ;
212
+ expect ( screen . queryByTestId ( 'reaction-selector' ) ) . not . toBeInTheDocument ( ) ;
213
+ } ) ;
214
+
215
+ it ( 'should unmount ReactionsSelector when closed pressed Esc button' , async ( ) => {
216
+ const { queryByTestId } = await renderMessageOptions ( {
217
+ channelStateOpts : {
218
+ channelCapabilities : { 'send-reaction' : true } ,
219
+ } ,
220
+ } ) ;
221
+ await act ( async ( ) => {
222
+ await fireEvent . click ( queryByTestId ( reactionActionTestId ) ) ;
223
+ } ) ;
224
+ await act ( async ( ) => {
225
+ await fireEvent . keyUp ( document , { charCode : 27 , code : 'Escape' , key : 'Escape' } ) ;
226
+ } ) ;
227
+ expect ( screen . queryByTestId ( 'reaction-selector' ) ) . not . toBeInTheDocument ( ) ;
228
+ } ) ;
229
+
230
+ it ( 'should unmount ReactionsSelector when closed on reaction selection and closeReactionSelectorOnClick enabled' , async ( ) => {
231
+ const { queryByTestId } = await renderMessageOptions ( {
232
+ channelStateOpts : {
233
+ channelCapabilities : { 'send-reaction' : true } ,
234
+ } ,
235
+ customMessageProps : {
236
+ closeReactionSelectorOnClick : true ,
237
+ } ,
238
+ } ) ;
239
+ await act ( async ( ) => {
240
+ await fireEvent . click ( queryByTestId ( reactionActionTestId ) ) ;
241
+ } ) ;
242
+ await act ( async ( ) => {
243
+ await fireEvent . click ( screen . queryAllByTestId ( 'select-reaction-button' ) [ 0 ] ) ;
244
+ } ) ;
245
+ expect ( screen . queryByTestId ( 'reaction-selector' ) ) . not . toBeInTheDocument ( ) ;
246
+ } ) ;
247
+
248
+ it ( 'should not unmount ReactionsSelector when closed on reaction selection and closeReactionSelectorOnClick enabled' , async ( ) => {
249
+ const { queryByTestId } = await renderMessageOptions ( {
250
+ channelStateOpts : {
251
+ channelCapabilities : { 'send-reaction' : true } ,
252
+ } ,
253
+ customMessageProps : {
254
+ closeReactionSelectorOnClick : false ,
255
+ } ,
256
+ } ) ;
257
+ await act ( async ( ) => {
258
+ await fireEvent . click ( queryByTestId ( reactionActionTestId ) ) ;
259
+ } ) ;
260
+ await act ( async ( ) => {
261
+ await fireEvent . click ( screen . queryAllByTestId ( 'select-reaction-button' ) [ 0 ] ) ;
262
+ } ) ;
263
+ expect ( screen . queryByTestId ( 'reaction-selector' ) ) . toBeInTheDocument ( ) ;
264
+ } ) ;
265
+
185
266
it ( 'should render message actions' , async ( ) => {
186
267
const { queryByTestId } = await renderMessageOptions ( {
187
268
channelStateOpts : { channelCapabilities : minimumCapabilitiesToRenderMessageActions } ,
0 commit comments