mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Reduce time to first byte for frontend index (#49396)
Cache template and manifest.json generation
This commit is contained in:
@@ -10,27 +10,26 @@ from homeassistant.components.frontend import (
|
||||
CONF_EXTRA_HTML_URL_ES5,
|
||||
CONF_JS_VERSION,
|
||||
CONF_THEMES,
|
||||
DEFAULT_THEME_COLOR,
|
||||
DOMAIN,
|
||||
EVENT_PANELS_UPDATED,
|
||||
THEMES_STORAGE_KEY,
|
||||
)
|
||||
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||
from homeassistant.const import HTTP_NOT_FOUND
|
||||
from homeassistant.const import HTTP_NOT_FOUND, HTTP_OK
|
||||
from homeassistant.loader import async_get_integration
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt
|
||||
|
||||
from tests.common import async_capture_events, async_fire_time_changed
|
||||
|
||||
CONFIG_THEMES = {
|
||||
DOMAIN: {
|
||||
CONF_THEMES: {
|
||||
"happy": {"primary-color": "red"},
|
||||
"dark": {"primary-color": "black"},
|
||||
}
|
||||
}
|
||||
MOCK_THEMES = {
|
||||
"happy": {"primary-color": "red", "app-header-background-color": "blue"},
|
||||
"dark": {"primary-color": "black"},
|
||||
}
|
||||
|
||||
CONFIG_THEMES = {DOMAIN: {CONF_THEMES: MOCK_THEMES}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def ignore_frontend_deps(hass):
|
||||
@@ -148,10 +147,7 @@ async def test_themes_api(hass, themes_ws_client):
|
||||
|
||||
assert msg["result"]["default_theme"] == "default"
|
||||
assert msg["result"]["default_dark_theme"] is None
|
||||
assert msg["result"]["themes"] == {
|
||||
"happy": {"primary-color": "red"},
|
||||
"dark": {"primary-color": "black"},
|
||||
}
|
||||
assert msg["result"]["themes"] == MOCK_THEMES
|
||||
|
||||
# safe mode
|
||||
hass.config.safe_mode = True
|
||||
@@ -474,3 +470,25 @@ async def test_static_paths(hass, mock_http_client):
|
||||
)
|
||||
assert resp.status == 302
|
||||
assert resp.headers["location"] == "/profile"
|
||||
|
||||
|
||||
async def test_manifest_json(hass, frontend_themes, mock_http_client):
|
||||
"""Test for fetching manifest.json."""
|
||||
resp = await mock_http_client.get("/manifest.json")
|
||||
assert resp.status == HTTP_OK
|
||||
assert "cache-control" not in resp.headers
|
||||
|
||||
json = await resp.json()
|
||||
assert json["theme_color"] == DEFAULT_THEME_COLOR
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "set_theme", {"name": "happy"}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
resp = await mock_http_client.get("/manifest.json")
|
||||
assert resp.status == HTTP_OK
|
||||
assert "cache-control" not in resp.headers
|
||||
|
||||
json = await resp.json()
|
||||
assert json["theme_color"] != DEFAULT_THEME_COLOR
|
||||
|
||||
Reference in New Issue
Block a user