Test extra javascript functionality in frontend (#102643)
parent
421832e09c
commit
e20d4abfe1
|
@ -8,6 +8,8 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.frontend import (
|
from homeassistant.components.frontend import (
|
||||||
|
CONF_EXTRA_JS_URL_ES5,
|
||||||
|
CONF_EXTRA_MODULE_URL,
|
||||||
CONF_THEMES,
|
CONF_THEMES,
|
||||||
DEFAULT_THEME_COLOR,
|
DEFAULT_THEME_COLOR,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -103,6 +105,22 @@ async def ws_client(hass, hass_ws_client, frontend):
|
||||||
return await hass_ws_client(hass)
|
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
|
@pytest.fixture
|
||||||
def mock_onboarded():
|
def mock_onboarded():
|
||||||
"""Mock that we're onboarded."""
|
"""Mock that we're onboarded."""
|
||||||
|
@ -356,6 +374,17 @@ async def test_missing_themes(hass: HomeAssistant, ws_client) -> None:
|
||||||
assert msg["result"]["themes"] == {}
|
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(
|
async def test_get_panels(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_http_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_http_client
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Reference in New Issue