@@ -16,7 +16,7 @@ limitations under the License.
16
16
17
17
import "@testing-library/jest-dom" ;
18
18
import React from "react" ;
19
- import { fireEvent , render , screen , waitFor } from "@testing-library/react" ;
19
+ import { act , fireEvent , render , screen , waitFor } from "@testing-library/react" ;
20
20
21
21
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext" ;
22
22
import RoomContext from "../../../../../src/contexts/RoomContext" ;
@@ -96,6 +96,53 @@ describe('EditWysiwygComposer', () => {
96
96
await waitFor ( ( ) =>
97
97
expect ( screen . getByRole ( 'textbox' ) ) . toContainHTML ( mockEvent . getContent ( ) [ 'body' ] ) ) ;
98
98
} ) ;
99
+
100
+ it ( 'Should ignore when formatted_body is not filled' , async ( ) => {
101
+ // When
102
+ const mockEvent = mkEvent ( {
103
+ type : "m.room.message" ,
104
+ room : 'myfakeroom' ,
105
+ user : 'myfakeuser' ,
106
+ content : {
107
+ "msgtype" : "m.text" ,
108
+ "body" : "Replying to this" ,
109
+ "format" : "org.matrix.custom.html" ,
110
+ } ,
111
+ event : true ,
112
+ } ) ;
113
+
114
+ const editorStateTransfer = new EditorStateTransfer ( mockEvent ) ;
115
+ customRender ( false , editorStateTransfer ) ;
116
+
117
+ // Then
118
+ await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'contentEditable' , "true" ) ) ;
119
+ } ) ;
120
+
121
+ it ( 'Should strip <mx-reply> tag from initial content' , async ( ) => {
122
+ // When
123
+ const mockEvent = mkEvent ( {
124
+ type : "m.room.message" ,
125
+ room : 'myfakeroom' ,
126
+ user : 'myfakeuser' ,
127
+ content : {
128
+ "msgtype" : "m.text" ,
129
+ "body" : "Replying to this" ,
130
+ "format" : "org.matrix.custom.html" ,
131
+ "formatted_body" : '<mx-reply>Reply</mx-reply>My content' ,
132
+ } ,
133
+ event : true ,
134
+ } ) ;
135
+
136
+ const editorStateTransfer = new EditorStateTransfer ( mockEvent ) ;
137
+ customRender ( false , editorStateTransfer ) ;
138
+ await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'contentEditable' , "true" ) ) ;
139
+
140
+ // Then
141
+ await waitFor ( ( ) => {
142
+ expect ( screen . getByRole ( 'textbox' ) ) . not . toContainHTML ( "<mx-reply>Reply</mx-reply>" ) ;
143
+ expect ( screen . getByRole ( 'textbox' ) ) . toContainHTML ( "My content" ) ;
144
+ } ) ;
145
+ } ) ;
99
146
} ) ;
100
147
101
148
describe ( 'Edit and save actions' , ( ) => {
@@ -180,14 +227,16 @@ describe('EditWysiwygComposer', () => {
180
227
expect ( screen . getByRole ( 'textbox' ) ) . not . toHaveFocus ( ) ;
181
228
182
229
// When we send an action that would cause us to get focus
183
- defaultDispatcher . dispatch ( {
184
- action : Action . FocusEditMessageComposer ,
185
- context : null ,
186
- } ) ;
187
- // (Send a second event to exercise the clearTimeout logic)
188
- defaultDispatcher . dispatch ( {
189
- action : Action . FocusEditMessageComposer ,
190
- context : null ,
230
+ act ( ( ) => {
231
+ defaultDispatcher . dispatch ( {
232
+ action : Action . FocusEditMessageComposer ,
233
+ context : null ,
234
+ } ) ;
235
+ // (Send a second event to exercise the clearTimeout logic)
236
+ defaultDispatcher . dispatch ( {
237
+ action : Action . FocusEditMessageComposer ,
238
+ context : null ,
239
+ } ) ;
191
240
} ) ;
192
241
193
242
// Wait for event dispatch to happen
0 commit comments