1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add WS command frontend/subscribe_extra_js (#119833)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Erik Montnemery
2024-06-18 16:18:42 +02:00
committed by GitHub
parent 0ca3f25c57
commit 7940303149
2 changed files with 93 additions and 6 deletions

View File

@@ -409,7 +409,11 @@ async def test_missing_themes(hass: HomeAssistant, ws_client) -> None:
@pytest.mark.usefixtures("mock_onboarded")
async def test_extra_js(hass: HomeAssistant, mock_http_client_with_extra_js) -> None:
async def test_extra_js(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_http_client_with_extra_js,
) -> None:
"""Test that extra javascript is loaded."""
async def get_response():
@@ -423,6 +427,13 @@ async def test_extra_js(hass: HomeAssistant, mock_http_client_with_extra_js) ->
assert '"/local/my_module.js"' in text
assert '"/local/my_es5.js"' in text
client = await hass_ws_client(hass)
await client.send_json_auto_id({"type": "frontend/subscribe_extra_js"})
msg = await client.receive_json()
assert msg["success"] is True
subscription_id = msg["id"]
# Test dynamically adding and removing extra javascript
add_extra_js_url(hass, "/local/my_module_2.js", False)
add_extra_js_url(hass, "/local/my_es5_2.js", True)
@@ -430,12 +441,38 @@ async def test_extra_js(hass: HomeAssistant, mock_http_client_with_extra_js) ->
assert '"/local/my_module_2.js"' in text
assert '"/local/my_es5_2.js"' in text
msg = await client.receive_json()
assert msg["id"] == subscription_id
assert msg["event"] == {
"change_type": "added",
"item": {"type": "module", "url": "/local/my_module_2.js"},
}
msg = await client.receive_json()
assert msg["id"] == subscription_id
assert msg["event"] == {
"change_type": "added",
"item": {"type": "es5", "url": "/local/my_es5_2.js"},
}
remove_extra_js_url(hass, "/local/my_module_2.js", False)
remove_extra_js_url(hass, "/local/my_es5_2.js", True)
text = await get_response()
assert '"/local/my_module_2.js"' not in text
assert '"/local/my_es5_2.js"' not in text
msg = await client.receive_json()
assert msg["id"] == subscription_id
assert msg["event"] == {
"change_type": "removed",
"item": {"type": "module", "url": "/local/my_module_2.js"},
}
msg = await client.receive_json()
assert msg["id"] == subscription_id
assert msg["event"] == {
"change_type": "removed",
"item": {"type": "es5", "url": "/local/my_es5_2.js"},
}
# Remove again should not raise
remove_extra_js_url(hass, "/local/my_module_2.js", False)
remove_extra_js_url(hass, "/local/my_es5_2.js", True)