@@ -6,7 +6,19 @@ mod tests {
66 field:: FormField , field_kind:: FieldKind , modal:: FormModal , state:: FormState ,
77 utils:: grapheme_count,
88 } ;
9- use ratatui:: prelude:: Rect ;
9+ use ratatui:: prelude:: { Buffer , Rect } ;
10+ use ratatui:: widgets:: Widget ;
11+
12+ fn buffer_text ( buf : & Buffer , area : Rect ) -> String {
13+ let mut text = String :: new ( ) ;
14+ for y in area. y ..area. y + area. height {
15+ for x in area. x ..area. x + area. width {
16+ text. push_str ( buf[ ( x, y) ] . symbol ( ) ) ;
17+ }
18+ text. push ( '\n' ) ;
19+ }
20+ text
21+ }
1022
1123 #[ test]
1224 fn test_field_builders ( ) {
@@ -153,6 +165,34 @@ mod tests {
153165 assert_eq ! ( centered. y, 12 ) ;
154166 }
155167
168+ #[ test]
169+ fn test_placeholder_shown_for_focused_empty_field ( ) {
170+ let fields = vec ! [ FormField :: text( "query" , "Query" ) . with_placeholder( "Search terms..." ) ] ;
171+ let state = FormState :: new ( "Search" , "search" , fields) ;
172+ let area = Rect :: new ( 0 , 0 , 80 , 24 ) ;
173+ let mut buf = Buffer :: empty ( area) ;
174+
175+ FormModal :: new ( & state) . render ( area, & mut buf) ;
176+
177+ let rendered = buffer_text ( & buf, area) ;
178+ assert ! ( rendered. contains( "Search terms..." ) ) ;
179+ }
180+
181+ #[ test]
182+ fn test_placeholder_hidden_when_submit_is_focused ( ) {
183+ let fields = vec ! [ FormField :: text( "query" , "Query" ) . with_placeholder( "Search terms..." ) ] ;
184+ let mut state = FormState :: new ( "Search" , "search" , fields) ;
185+ state. focus_next ( ) ;
186+ let area = Rect :: new ( 0 , 0 , 80 , 24 ) ;
187+ let mut buf = Buffer :: empty ( area) ;
188+
189+ FormModal :: new ( & state) . render ( area, & mut buf) ;
190+
191+ let rendered = buffer_text ( & buf, area) ;
192+ assert ! ( !rendered. contains( "Search terms..." ) ) ;
193+ assert ! ( rendered. contains( "[ Submit ]" ) ) ;
194+ }
195+
156196 #[ test]
157197 fn test_handle_paste_text_field ( ) {
158198 let fields = vec ! [ FormField :: text( "api_key" , "API Key" ) ] ;
0 commit comments