mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Add test
This commit is contained in:
parent
0ccabe9f2c
commit
7c159b64a4
33
tests/helpers/snapshots/test_selector.ambr
Normal file
33
tests/helpers/snapshots/test_selector.ambr
Normal file
@ -0,0 +1,33 @@
|
||||
# serializer version: 1
|
||||
# name: test_object_selector_uses_selectors
|
||||
dict({
|
||||
'selector': dict({
|
||||
'object': dict({
|
||||
'description_field': 'percentage',
|
||||
'fields': dict({
|
||||
'name': dict({
|
||||
'required': True,
|
||||
'selector': dict({
|
||||
'text': dict({
|
||||
'multiline': False,
|
||||
'multiple': False,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
'percentage': dict({
|
||||
'selector': dict({
|
||||
'number': dict({
|
||||
'max': 100.0,
|
||||
'min': 0.0,
|
||||
'mode': 'slider',
|
||||
'step': 1.0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
'label_field': 'name',
|
||||
'multiple': True,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
@ -4,6 +4,7 @@ from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers import selector
|
||||
@ -618,6 +619,43 @@ def test_object_selector_schema(schema, valid_selections, invalid_selections) ->
|
||||
_test_selector("object", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
def test_object_selector_uses_selectors(snapshot: SnapshotAssertion) -> None:
|
||||
"""Test ObjectSelector custom serializer for using Selector in ObjectSelectorField."""
|
||||
|
||||
selector_type = "object"
|
||||
schema = {
|
||||
"fields": {
|
||||
"name": {
|
||||
"required": True,
|
||||
"selector": selector.TextSelector(),
|
||||
},
|
||||
"percentage": {
|
||||
"selector": selector.NumberSelector(
|
||||
selector.NumberSelectorConfig(min=0, max=100)
|
||||
),
|
||||
},
|
||||
},
|
||||
"multiple": True,
|
||||
"label_field": "name",
|
||||
"description_field": "percentage",
|
||||
}
|
||||
|
||||
# Validate selector configuration
|
||||
config = {selector_type: schema}
|
||||
selector.validate_selector(config)
|
||||
selector_instance = selector.selector(config)
|
||||
|
||||
# Serialize selector
|
||||
selector_instance = selector.selector({selector_type: schema})
|
||||
assert selector_instance.serialize() != {
|
||||
"selector": {selector_type: selector_instance.config}
|
||||
}
|
||||
assert selector_instance.serialize() == snapshot()
|
||||
|
||||
# Test serialized selector can be dumped to YAML
|
||||
yaml_util.dump(selector_instance.serialize())
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user