From e20d4abfe1676d1e91e0ee297e45ceb6d6d119a3 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 24 Oct 2023 11:31:16 +0200 Subject: [PATCH] Test extra javascript functionality in frontend (#102643) --- tests/components/frontend/test_init.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index e6ef6518d1b..0c6b893b4b9 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -8,6 +8,8 @@ from unittest.mock import patch import pytest from homeassistant.components.frontend import ( + CONF_EXTRA_JS_URL_ES5, + CONF_EXTRA_MODULE_URL, CONF_THEMES, DEFAULT_THEME_COLOR, DOMAIN, @@ -103,6 +105,22 @@ async def ws_client(hass, hass_ws_client, frontend): return await hass_ws_client(hass) +@pytest.fixture +async def mock_http_client_with_extra_js(hass, aiohttp_client, ignore_frontend_deps): + """Start the Home Assistant HTTP component.""" + assert await async_setup_component( + hass, + "frontend", + { + DOMAIN: { + CONF_EXTRA_MODULE_URL: ["/local/my_module.js"], + CONF_EXTRA_JS_URL_ES5: ["/local/my_es5.js"], + } + }, + ) + return await aiohttp_client(hass.http.app) + + @pytest.fixture def mock_onboarded(): """Mock that we're onboarded.""" @@ -356,6 +374,17 @@ async def test_missing_themes(hass: HomeAssistant, ws_client) -> None: assert msg["result"]["themes"] == {} +async def test_extra_js(mock_http_client_with_extra_js, mock_onboarded): + """Test that extra javascript is loaded.""" + resp = await mock_http_client_with_extra_js.get("") + assert resp.status == 200 + assert "cache-control" not in resp.headers + + text = await resp.text() + assert '"/local/my_module.js"' in text + assert '"/local/my_es5.js"' in text + + async def test_get_panels( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_http_client ) -> None: