@@ -51,11 +51,12 @@ describe('SendWysiwygComposer', () => {
51
51
onChange = ( _content : string ) => void 0 ,
52
52
onSend = ( ) => void 0 ,
53
53
disabled = false ,
54
- isRichTextEnabled = true ) => {
54
+ isRichTextEnabled = true ,
55
+ placeholder ?: string ) => {
55
56
return render (
56
57
< MatrixClientContext . Provider value = { mockClient } >
57
58
< RoomContext . Provider value = { defaultRoomContext } >
58
- < SendWysiwygComposer onChange = { onChange } onSend = { onSend } disabled = { disabled } isRichTextEnabled = { isRichTextEnabled } menuPosition = { aboveLeftOf ( { top : 0 , bottom : 0 , right : 0 } ) } />
59
+ < SendWysiwygComposer onChange = { onChange } onSend = { onSend } disabled = { disabled } isRichTextEnabled = { isRichTextEnabled } menuPosition = { aboveLeftOf ( { top : 0 , bottom : 0 , right : 0 } ) } placeholder = { placeholder } />
59
60
</ RoomContext . Provider >
60
61
</ MatrixClientContext . Provider > ,
61
62
) ;
@@ -164,5 +165,62 @@ describe('SendWysiwygComposer', () => {
164
165
expect ( screen . getByRole ( 'textbox' ) ) . not . toHaveFocus ( ) ;
165
166
} ) ;
166
167
} ) ;
168
+
169
+ describe . each ( [
170
+ { isRichTextEnabled : true } ,
171
+ { isRichTextEnabled : false } ,
172
+ ] ) ( 'Placeholder when %s' ,
173
+ ( { isRichTextEnabled } ) => {
174
+ afterEach ( ( ) => {
175
+ jest . resetAllMocks ( ) ;
176
+ } ) ;
177
+
178
+ it ( 'Should not has placeholder' , async ( ) => {
179
+ // When
180
+ console . log ( 'here' ) ;
181
+ customRender ( jest . fn ( ) , jest . fn ( ) , false , isRichTextEnabled ) ;
182
+ await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'contentEditable' , "true" ) ) ;
183
+
184
+ // Then
185
+ expect ( screen . getByRole ( 'textbox' ) ) . not . toHaveClass ( "mx_WysiwygComposer_Editor_content_placeholder" ) ;
186
+ } ) ;
187
+
188
+ it ( 'Should has placeholder' , async ( ) => {
189
+ // When
190
+ customRender ( jest . fn ( ) , jest . fn ( ) , false , isRichTextEnabled , 'my placeholder' ) ;
191
+ await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'contentEditable' , "true" ) ) ;
192
+
193
+ // Then
194
+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveClass ( "mx_WysiwygComposer_Editor_content_placeholder" ) ;
195
+ } ) ;
196
+
197
+ it ( 'Should display or not placeholder when editor content change' , async ( ) => {
198
+ // When
199
+ customRender ( jest . fn ( ) , jest . fn ( ) , false , isRichTextEnabled , 'my placeholder' ) ;
200
+ await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'contentEditable' , "true" ) ) ;
201
+ screen . getByRole ( 'textbox' ) . innerHTML = 'f' ;
202
+ fireEvent . input ( screen . getByRole ( 'textbox' ) , {
203
+ data : 'f' ,
204
+ inputType : 'insertText' ,
205
+ } ) ;
206
+
207
+ // Then
208
+ await waitFor ( ( ) =>
209
+ expect ( screen . getByRole ( 'textbox' ) )
210
+ . not . toHaveClass ( "mx_WysiwygComposer_Editor_content_placeholder" ) ,
211
+ ) ;
212
+
213
+ // When
214
+ screen . getByRole ( 'textbox' ) . innerHTML = '' ;
215
+ fireEvent . input ( screen . getByRole ( 'textbox' ) , {
216
+ inputType : 'deleteContentBackward' ,
217
+ } ) ;
218
+
219
+ // Then
220
+ await waitFor ( ( ) =>
221
+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveClass ( "mx_WysiwygComposer_Editor_content_placeholder" ) ,
222
+ ) ;
223
+ } ) ;
224
+ } ) ;
167
225
} ) ;
168
226
0 commit comments