From f40897b54cb4afcc6a0e786fdb7e692e6707ab6a Mon Sep 17 00:00:00 2001
From: Tsvi Mostovicz <ttmost@gmail.com>
Date: Thu, 11 Jul 2024 12:17:12 +0300
Subject: [PATCH] Add Jewish Calendar reconfiguration test (#118833)

* Revert "Remove flaky tests"

This reverts commit c4de9fdcbeca6075574b578e05916a08231647af.

* Change reconfigure test to be based on data

* Don't assert using internals

* Fix assertions to be on config entry
---
 .../jewish_calendar/test_config_flow.py       | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tests/components/jewish_calendar/test_config_flow.py b/tests/components/jewish_calendar/test_config_flow.py
index 3189571a5a7..466d3a1e4f0 100644
--- a/tests/components/jewish_calendar/test_config_flow.py
+++ b/tests/components/jewish_calendar/test_config_flow.py
@@ -9,6 +9,7 @@ from homeassistant.components.jewish_calendar.const import (
     CONF_CANDLE_LIGHT_MINUTES,
     CONF_DIASPORA,
     CONF_HAVDALAH_OFFSET_MINUTES,
+    DEFAULT_CANDLE_LIGHT,
     DEFAULT_DIASPORA,
     DEFAULT_LANGUAGE,
     DOMAIN,
@@ -138,3 +139,28 @@ async def test_options(hass: HomeAssistant, mock_config_entry: MockConfigEntry)
     assert len(entries) == 1
     assert entries[0].options[CONF_CANDLE_LIGHT_MINUTES] == 25
     assert entries[0].options[CONF_HAVDALAH_OFFSET_MINUTES] == 34
+
+
+async def test_options_reconfigure(
+    hass: HomeAssistant, mock_config_entry: MockConfigEntry
+) -> None:
+    """Test that updating the options of the Jewish Calendar integration triggers a value update."""
+    mock_config_entry.add_to_hass(hass)
+    await hass.config_entries.async_setup(mock_config_entry.entry_id)
+    await hass.async_block_till_done()
+    assert CONF_CANDLE_LIGHT_MINUTES not in mock_config_entry.options
+
+    # Update the CONF_CANDLE_LIGHT_MINUTES option to a new value
+    result = await hass.config_entries.options.async_init(mock_config_entry.entry_id)
+    result = await hass.config_entries.options.async_configure(
+        result["flow_id"],
+        user_input={
+            CONF_CANDLE_LIGHT_MINUTES: DEFAULT_CANDLE_LIGHT + 1,
+        },
+    )
+    assert result["result"]
+
+    # The value of the "upcoming_shabbat_candle_lighting" sensor should be the new value
+    assert (
+        mock_config_entry.options[CONF_CANDLE_LIGHT_MINUTES] == DEFAULT_CANDLE_LIGHT + 1
+    )
-- 
GitLab