mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
parent
23809bff64
commit
a943b207ba
@ -61,7 +61,7 @@ def async_setup(hass, config):
|
|||||||
name, panel_path,
|
name, panel_path,
|
||||||
sidebar_title=panel.get(CONF_SIDEBAR_TITLE),
|
sidebar_title=panel.get(CONF_SIDEBAR_TITLE),
|
||||||
sidebar_icon=panel.get(CONF_SIDEBAR_ICON),
|
sidebar_icon=panel.get(CONF_SIDEBAR_ICON),
|
||||||
url_path=panel.get(CONF_URL_PATH),
|
frontend_url_path=panel.get(CONF_URL_PATH),
|
||||||
config=panel.get(CONF_CONFIG),
|
config=panel.get(CONF_CONFIG),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,21 +5,19 @@ from unittest.mock import Mock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
|
from homeassistant.components import frontend
|
||||||
|
|
||||||
from tests.common import mock_coro, mock_component
|
from tests.common import mock_component
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(autouse=True)
|
||||||
def mock_register(hass):
|
def mock_frontend_loaded(hass):
|
||||||
"""Mock the frontend component being loaded and yield register method."""
|
"""Mock frontend is loaded."""
|
||||||
mock_component(hass, 'frontend')
|
mock_component(hass, 'frontend')
|
||||||
with patch('homeassistant.components.frontend.async_register_panel',
|
|
||||||
return_value=mock_coro()) as mock_register:
|
|
||||||
yield mock_register
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_webcomponent_custom_path_not_found(hass, mock_register):
|
def test_webcomponent_custom_path_not_found(hass):
|
||||||
"""Test if a web component is found in config panels dir."""
|
"""Test if a web component is found in config panels dir."""
|
||||||
filename = 'mock.file'
|
filename = 'mock.file'
|
||||||
|
|
||||||
@ -39,11 +37,11 @@ def test_webcomponent_custom_path_not_found(hass, mock_register):
|
|||||||
hass, 'panel_custom', config
|
hass, 'panel_custom', config
|
||||||
)
|
)
|
||||||
assert not result
|
assert not result
|
||||||
assert not mock_register.called
|
assert len(hass.data.get(frontend.DATA_PANELS, {})) == 0
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_webcomponent_custom_path(hass, mock_register):
|
def test_webcomponent_custom_path(hass):
|
||||||
"""Test if a web component is found in config panels dir."""
|
"""Test if a web component is found in config panels dir."""
|
||||||
filename = 'mock.file'
|
filename = 'mock.file'
|
||||||
|
|
||||||
@ -65,15 +63,15 @@ def test_webcomponent_custom_path(hass, mock_register):
|
|||||||
)
|
)
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert mock_register.called
|
panels = hass.data.get(frontend.DATA_PANELS, [])
|
||||||
|
|
||||||
args = mock_register.mock_calls[0][1]
|
assert len(panels) == 1
|
||||||
assert args == (hass, 'todomvc', filename)
|
assert 'nice_url' in panels
|
||||||
|
|
||||||
kwargs = mock_register.mock_calls[0][2]
|
panel = panels['nice_url']
|
||||||
assert kwargs == {
|
|
||||||
'config': 5,
|
assert panel.config == 5
|
||||||
'url_path': 'nice_url',
|
assert panel.frontend_url_path == 'nice_url'
|
||||||
'sidebar_icon': 'mdi:iconicon',
|
assert panel.sidebar_icon == 'mdi:iconicon'
|
||||||
'sidebar_title': 'Sidebar Title'
|
assert panel.sidebar_title == 'Sidebar Title'
|
||||||
}
|
assert panel.path == filename
|
||||||
|
Loading…
x
Reference in New Issue
Block a user