Add support for JS modules in custom panels (#16096)

* Added backend support for JavaScript modules in custom panels.

* Fixed test_panel_custom.py

* Delete core.entity_registry

* Update panel_custom.py

* Corrected panel_custom.py with module_url.

* Rebase

* Missed elif

* Add vol.Exclusive module_url

* Correct vol.Exclusive usage

* Test for js module

* Corrected line continuation indentation

* Added webcomponent path to exclusive group

* Corrected line length

* Line break

* Test for conflicting url options

* Self -> hass fix

* Fix self -> hass again

* Use assert_setup_component

* Setup missing

* Correct test

* Fix again

* Fix

* Mising async

* Fix

* test real

* Test real

* Final

* check

* Final check

* safety

* Final commit and check

* Removed unused dependencies

* Test for multiple url options in config
This commit is contained in:
squidwardy authored and Paulus Schoutsen committed 2018-08-23 11:14:18 +02:00
1 parent ced5eeacc2
commit 8e173f1658
2 files changed
+93 -6

No files matched your search

+70
View File
@@ -114,3 +114,73 @@ async def test_js_webcomponent(hass):
assert panel.frontend_url_path == 'nice_url'
assert panel.sidebar_icon == 'mdi:iconicon'
assert panel.sidebar_title == 'Sidebar Title'
async def test_module_webcomponent(hass):
"""Test if a js module is found in config panels dir."""
config = {
'panel_custom': {
'name': 'todo-mvc',
'module_url': '/local/bla.js',
'sidebar_title': 'Sidebar Title',
'sidebar_icon': 'mdi:iconicon',
'url_path': 'nice_url',
'config': {
'hello': 'world',
},
'embed_iframe': True,
'trust_external_script': True,
}
}
result = await setup.async_setup_component(
hass, 'panel_custom', config
)
assert result
panels = hass.data.get(frontend.DATA_PANELS, [])
assert panels
assert 'nice_url' in panels
panel = panels['nice_url']
assert panel.config == {
'hello': 'world',
'_panel_custom': {
'module_url': '/local/bla.js',
'name': 'todo-mvc',
'embed_iframe': True,
'trust_external': True,
}
}
assert panel.frontend_url_path == 'nice_url'
assert panel.sidebar_icon == 'mdi:iconicon'
assert panel.sidebar_title == 'Sidebar Title'
async def test_url_option_conflict(hass):
"""Test config with multiple url options."""
to_try = [
{'panel_custom': {
'name': 'todo-mvc',
'module_url': '/local/bla.js',
'js_url': '/local/bla.js',
}
}, {'panel_custom': {
'name': 'todo-mvc',
'webcomponent_path': '/local/bla.html',
'js_url': '/local/bla.js',
}}, {'panel_custom': {
'name': 'todo-mvc',
'webcomponent_path': '/local/bla.html',
'module_url': '/local/bla.js',
'js_url': '/local/bla.js',
}}
]
for config in to_try:
result = await setup.async_setup_component(
hass, 'panel_custom', config
)
assert not result