@@ -133,6 +133,57 @@ async def async_step_init(self, user_input=None):
133133 assert form ["errors" ] == {"username" : "Should be unique." }
134134
135135
136+ async def test_form_shows_with_added_suggested_values (manager : MockFlowManager ) -> None :
137+ """Test that we can show a form with suggested values."""
138+ schema = vol .Schema (
139+ {
140+ vol .Required ("username" ): str ,
141+ vol .Required ("password" ): str ,
142+ vol .Required ("section_1" ): data_entry_flow .section (
143+ vol .Schema (
144+ {
145+ vol .Optional ("full_name" ): str ,
146+ }
147+ ),
148+ {"collapsed" : False },
149+ ),
150+ }
151+ )
152+
153+ @manager .mock_reg_handler ("test" )
154+ class TestFlow (data_entry_flow .FlowHandler ):
155+ async def async_step_init (self , user_input = None ):
156+ data_schema = self .add_suggested_values_to_schema (
157+ schema ,
158+ {
159+ "username" : "doej" ,
160+ "password" : "verySecret1" ,
161+ "section_1" : {"full_name" : "John Doe" },
162+ },
163+ )
164+ return self .async_show_form (
165+ step_id = "init" ,
166+ data_schema = data_schema ,
167+ )
168+
169+ form = await manager .async_init ("test" )
170+ assert form ["type" ] == data_entry_flow .FlowResultType .FORM
171+ assert form ["data_schema" ].schema == schema .schema
172+ markers = list (form ["data_schema" ].schema )
173+ assert len (markers ) == 3
174+ assert markers [0 ] == "username"
175+ assert markers [0 ].description == {"suggested_value" : "doej" }
176+ assert markers [1 ] == "password"
177+ assert markers [1 ].description == {"suggested_value" : "verySecret1" }
178+ assert markers [2 ] == "section_1"
179+ section_validator = form ["data_schema" ].schema ["section_1" ]
180+ assert isinstance (section_validator , data_entry_flow .section )
181+ section_markers = list (section_validator .schema .schema )
182+ assert len (section_markers ) == 1
183+ assert section_markers [0 ] == "full_name"
184+ assert section_markers [0 ].description == {"suggested_value" : "John Doe" }
185+
186+
136187async def test_abort_removes_instance (manager : MockFlowManager ) -> None :
137188 """Test that abort removes the flow from progress."""
138189
0 commit comments