mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add tests of frontend.add_extra_js_url (#119826)
This commit is contained in:
parent
442554c223
commit
c0a3b507c0
@ -322,7 +322,10 @@ def async_remove_panel(hass: HomeAssistant, frontend_url_path: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def add_extra_js_url(hass: HomeAssistant, url: str, es5: bool = False) -> None:
|
def add_extra_js_url(hass: HomeAssistant, url: str, es5: bool = False) -> None:
|
||||||
"""Register extra js or module url to load."""
|
"""Register extra js or module url to load.
|
||||||
|
|
||||||
|
This function allows custom integrations to register extra js or module.
|
||||||
|
"""
|
||||||
key = DATA_EXTRA_JS_URL_ES5 if es5 else DATA_EXTRA_MODULE_URL
|
key = DATA_EXTRA_JS_URL_ES5 if es5 else DATA_EXTRA_MODULE_URL
|
||||||
hass.data[key].add(url)
|
hass.data[key].add(url)
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.components.frontend import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
EVENT_PANELS_UPDATED,
|
EVENT_PANELS_UPDATED,
|
||||||
THEMES_STORAGE_KEY,
|
THEMES_STORAGE_KEY,
|
||||||
|
add_extra_js_url,
|
||||||
async_register_built_in_panel,
|
async_register_built_in_panel,
|
||||||
async_remove_panel,
|
async_remove_panel,
|
||||||
)
|
)
|
||||||
@ -416,6 +417,17 @@ async def test_extra_js(hass: HomeAssistant, mock_http_client_with_extra_js) ->
|
|||||||
assert '"/local/my_module.js"' in text
|
assert '"/local/my_module.js"' in text
|
||||||
assert '"/local/my_es5.js"' in text
|
assert '"/local/my_es5.js"' in text
|
||||||
|
|
||||||
|
# Test dynamically adding extra javascript
|
||||||
|
add_extra_js_url(hass, "/local/my_module_2.js", False)
|
||||||
|
add_extra_js_url(hass, "/local/my_es5_2.js", True)
|
||||||
|
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_2.js"' in text
|
||||||
|
assert '"/local/my_es5_2.js"' in text
|
||||||
|
|
||||||
# safe mode
|
# safe mode
|
||||||
hass.config.safe_mode = True
|
hass.config.safe_mode = True
|
||||||
resp = await mock_http_client_with_extra_js.get("")
|
resp = await mock_http_client_with_extra_js.get("")
|
||||||
@ -426,6 +438,17 @@ async def test_extra_js(hass: HomeAssistant, mock_http_client_with_extra_js) ->
|
|||||||
assert '"/local/my_module.js"' not in text
|
assert '"/local/my_module.js"' not in text
|
||||||
assert '"/local/my_es5.js"' not in text
|
assert '"/local/my_es5.js"' not in text
|
||||||
|
|
||||||
|
# Test dynamically adding extra javascript
|
||||||
|
add_extra_js_url(hass, "/local/my_module_2.js", False)
|
||||||
|
add_extra_js_url(hass, "/local/my_es5_2.js", True)
|
||||||
|
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_2.js"' not in text
|
||||||
|
assert '"/local/my_es5_2.js"' not 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user