@@ -46,12 +46,12 @@ function generateAliceMessage(messageOptions) {
4646 } ) ;
4747}
4848
49- async function renderMessageOptions (
50- customMessageProps = { } ,
49+ async function renderMessageOptions ( {
5150 channelConfig,
52- customOptionsProps = { } ,
5351 channelStateOpts = { } ,
54- ) {
52+ customMessageProps = { } ,
53+ customOptionsProps = { } ,
54+ } ) {
5555 const client = await getTestClientWithUser ( alice ) ;
5656 const channel = generateChannel ( { getConfig : ( ) => channelConfig , state : { membership : { } } } ) ;
5757
@@ -94,7 +94,9 @@ describe('<MessageOptions />', () => {
9494 beforeEach ( jest . clearAllMocks ) ;
9595 it ( 'should not render message options when there is no message set' , async ( ) => {
9696 const { queryByTestId } = await renderMessageOptions ( {
97- message : { } ,
97+ customMessageProps : {
98+ message : { } ,
99+ } ,
98100 } ) ;
99101 expect ( queryByTestId ( / m e s s a g e - o p t i o n s / ) ) . not . toBeInTheDocument ( ) ;
100102 } ) ;
@@ -109,70 +111,80 @@ describe('<MessageOptions />', () => {
109111 'should not render message options when message is of %s %s and is from current user.' ,
110112 async ( key , value ) => {
111113 const message = generateAliceMessage ( { [ key ] : value } ) ;
112- const { queryByTestId } = await renderMessageOptions ( { message } ) ;
114+ const { queryByTestId } = await renderMessageOptions ( { customMessageProps : { message } } ) ;
113115 expect ( queryByTestId ( / m e s s a g e - o p t i o n s / ) ) . not . toBeInTheDocument ( ) ;
114116 } ,
115117 ) ;
116118
117119 it ( 'should not render message options when it is parent message in a thread' , async ( ) => {
118120 const { queryByTestId } = await renderMessageOptions ( {
119- initialMessage : true ,
121+ customMessageProps : {
122+ initialMessage : true ,
123+ } ,
120124 } ) ;
121125 expect ( queryByTestId ( / m e s s a g e - o p t i o n s / ) ) . not . toBeInTheDocument ( ) ;
122126 } ) ;
123127
124128 it ( 'should display thread actions when message is not displayed in a thread list and channel has replies configured' , async ( ) => {
125- const { getByTestId } = await renderMessageOptions (
126- defaultMessageProps ,
127- { } ,
128- { } ,
129- { channelCapabilities : { 'send-reply' : true } , channelConfig : { replies : true } } ,
130- ) ;
129+ const { getByTestId } = await renderMessageOptions ( {
130+ channelStateOpts : {
131+ channelCapabilities : { 'send-reply' : true } ,
132+ channelConfig : { replies : true } ,
133+ } ,
134+ customMessageProps : defaultMessageProps ,
135+ } ) ;
131136 expect ( getByTestId ( threadActionTestId ) ) . toBeInTheDocument ( ) ;
132137 } ) ;
133138
134139 it ( 'should not display thread actions when message is in a thread list' , async ( ) => {
135- const { queryByTestId } = await renderMessageOptions ( { threadList : true } , { replies : true } ) ;
140+ const { queryByTestId } = await renderMessageOptions ( {
141+ channelConfig : { replies : true } ,
142+ customMessageProps : { threadList : true } ,
143+ } ) ;
136144 expect ( queryByTestId ( threadActionTestId ) ) . not . toBeInTheDocument ( ) ;
137145 } ) ;
138146
139147 it ( 'should not display thread actions when channel does not have replies enabled' , async ( ) => {
140- const { queryByTestId } = await renderMessageOptions ( { } , { replies : false } ) ;
148+ const { queryByTestId } = await renderMessageOptions ( { channelConfig : { replies : false } } ) ;
141149 expect ( queryByTestId ( threadActionTestId ) ) . not . toBeInTheDocument ( ) ;
142150 } ) ;
143151
144152 it ( 'should trigger open thread handler when custom thread action is set and thread action is clicked' , async ( ) => {
145153 const handleOpenThread = jest . fn ( ( ) => { } ) ;
146154 const message = generateMessage ( ) ;
147- const { getByTestId } = await renderMessageOptions (
148- { message, openThread : handleOpenThread , threadList : false } ,
149- { } ,
150- { } ,
151- { channelCapabilities : { 'send-reply' : true } , channelConfig : { replies : true } } ,
152- ) ;
155+ const { getByTestId } = await renderMessageOptions ( {
156+ channelStateOpts : {
157+ channelCapabilities : { 'send-reply' : true } ,
158+ channelConfig : { replies : true } ,
159+ } ,
160+ customMessageProps : { message, openThread : handleOpenThread , threadList : false } ,
161+ } ) ;
153162 expect ( handleOpenThread ) . not . toHaveBeenCalled ( ) ;
154163 fireEvent . click ( getByTestId ( threadActionTestId ) ) ;
155164 // eslint-disable-next-line jest/prefer-called-with
156165 expect ( handleOpenThread ) . toHaveBeenCalled ( ) ;
157166 } ) ;
158167
159168 it ( 'should display reactions action when channel has reactions enabled' , async ( ) => {
160- const { getByTestId } = await renderMessageOptions (
161- { } ,
162- { } ,
163- { } ,
164- { channelCapabilities : { 'send-reaction' : true } , channelConfig : { reactions : true } } ,
165- ) ;
169+ const { getByTestId } = await renderMessageOptions ( {
170+ channelStateOpts : {
171+ channelCapabilities : { 'send-reaction' : true } ,
172+ channelConfig : { reactions : true } ,
173+ } ,
174+ } ) ;
166175 expect ( getByTestId ( reactionActionTestId ) ) . toBeInTheDocument ( ) ;
167176 } ) ;
168177
169178 it ( 'should not display reactions action when channel has reactions disabled' , async ( ) => {
170- const { queryByTestId } = await renderMessageOptions ( { } , { reactions : false } ) ;
179+ const { queryByTestId } = await renderMessageOptions ( { channelConfig : { reactions : false } } ) ;
171180 expect ( queryByTestId ( reactionActionTestId ) ) . not . toBeInTheDocument ( ) ;
172181 } ) ;
173182
174183 it ( 'should render message actions' , async ( ) => {
175- await renderMessageOptions ( ) ;
184+ const minimumCapabilitiesToRenderMessageActions = { 'delete-any-message' : true } ;
185+ await renderMessageOptions ( {
186+ channelStateOpts : { channelCapabilities : minimumCapabilitiesToRenderMessageActions } ,
187+ } ) ;
176188 // eslint-disable-next-line jest/prefer-called-with
177189 expect ( MessageActionsMock ) . toHaveBeenCalled ( ) ;
178190 } ) ;
0 commit comments