Test extra javascript functionality in frontend (#102643)

pull/102606/head
Erik Montnemery 2023-10-24 11:31:16 +02:00 committed by GitHub
parent 421832e09c
commit e20d4abfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 0 deletions

View File

@ -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: