mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 20:25:07 +02:00
Improve Google Cast options flow (#50028)
This commit is contained in:
@@ -153,7 +153,8 @@ def get_suggested(schema, key):
|
||||
)
|
||||
async def test_option_flow(hass, parameter_data):
|
||||
"""Test config flow options."""
|
||||
all_parameters = ["ignore_cec", "known_hosts", "uuid"]
|
||||
basic_parameters = ["known_hosts"]
|
||||
advanced_parameters = ["ignore_cec", "uuid"]
|
||||
parameter, initial, suggested, user_input, updated = parameter_data
|
||||
|
||||
data = {
|
||||
@@ -170,32 +171,61 @@ async def test_option_flow(hass, parameter_data):
|
||||
# Test ignore_cec and uuid options are hidden if advanced options are disabled
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "options"
|
||||
assert result["step_id"] == "basic_options"
|
||||
data_schema = result["data_schema"].schema
|
||||
assert set(data_schema) == {"known_hosts"}
|
||||
orig_data = dict(config_entry.data)
|
||||
|
||||
# Reconfigure ignore_cec, known_hosts, uuid
|
||||
# Reconfigure known_hosts
|
||||
context = {"source": config_entries.SOURCE_USER, "show_advanced_options": True}
|
||||
result = await hass.config_entries.options.async_init(
|
||||
config_entry.entry_id, context=context
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "options"
|
||||
assert result["step_id"] == "basic_options"
|
||||
data_schema = result["data_schema"].schema
|
||||
for other_param in all_parameters:
|
||||
for other_param in basic_parameters:
|
||||
if other_param == parameter:
|
||||
continue
|
||||
assert get_suggested(data_schema, other_param) == ""
|
||||
assert get_suggested(data_schema, parameter) == suggested
|
||||
if parameter in basic_parameters:
|
||||
assert get_suggested(data_schema, parameter) == suggested
|
||||
|
||||
user_input_dict = {}
|
||||
if parameter in basic_parameters:
|
||||
user_input_dict[parameter] = user_input
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={parameter: user_input},
|
||||
user_input=user_input_dict,
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "advanced_options"
|
||||
for other_param in basic_parameters:
|
||||
if other_param == parameter:
|
||||
continue
|
||||
assert config_entry.data[other_param] == []
|
||||
# No update yet
|
||||
assert config_entry.data[parameter] == initial
|
||||
|
||||
# Reconfigure ignore_cec, uuid
|
||||
data_schema = result["data_schema"].schema
|
||||
for other_param in advanced_parameters:
|
||||
if other_param == parameter:
|
||||
continue
|
||||
assert get_suggested(data_schema, other_param) == ""
|
||||
if parameter in advanced_parameters:
|
||||
assert get_suggested(data_schema, parameter) == suggested
|
||||
|
||||
user_input_dict = {}
|
||||
if parameter in advanced_parameters:
|
||||
user_input_dict[parameter] = user_input
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=user_input_dict,
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] is None
|
||||
for other_param in all_parameters:
|
||||
for other_param in advanced_parameters:
|
||||
if other_param == parameter:
|
||||
continue
|
||||
assert config_entry.data[other_param] == []
|
||||
@@ -209,12 +239,10 @@ async def test_option_flow(hass, parameter_data):
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] is None
|
||||
assert config_entry.data == {
|
||||
**orig_data,
|
||||
"ignore_cec": [],
|
||||
"known_hosts": [],
|
||||
"uuid": [],
|
||||
}
|
||||
expected_data = {**orig_data, "known_hosts": []}
|
||||
if parameter in advanced_parameters:
|
||||
expected_data[parameter] = updated
|
||||
assert dict(config_entry.data) == expected_data
|
||||
|
||||
|
||||
async def test_known_hosts(hass, castbrowser_mock, castbrowser_constructor_mock):
|
||||
|
Reference in New Issue
Block a user