Exemple #1
0
def test_debug_log_dynamic_children_must_have_keys(caplog):
    idom.vdom("div", [idom.vdom("div")])
    assert len(caplog.records) == 1
    assert caplog.records[0].message.startswith("Key not specified for child")

    caplog.records.clear()

    @idom.component
    def MyComponent():
        return idom.vdom("div")

    idom.vdom("div", [MyComponent()])
    assert len(caplog.records) == 1
    assert caplog.records[0].message.startswith("Key not specified for child")
Exemple #2
0
async def test_callable_attributes_are_cast_to_event_handlers():
    params_from_calls = []

    node = idom.vdom("div",
                     {"onEvent": lambda *args: params_from_calls.append(args)})

    event_handlers = node.pop("eventHandlers")
    assert node == {"tagName": "div"}

    handler = event_handlers["onEvent"]
    assert event_handlers == {"onEvent": EventHandler(handler.function)}

    await handler.function([1, 2])
    await handler.function([3, 4, 5])
    assert params_from_calls == [(1, 2), (3, 4, 5)]
Exemple #3
0
async def test_event_handlers_and_callable_attributes_are_automatically_merged(
):
    calls = []

    node = idom.vdom(
        "div",
        {"onEvent": lambda: calls.append("callable_attr")},
        event_handlers={
            "onEvent":
            EventHandler(lambda data: calls.append("normal_event_handler"))
        },
    )

    event_handlers = node.pop("eventHandlers")
    assert node == {"tagName": "div"}

    handler = event_handlers["onEvent"]
    assert event_handlers == {"onEvent": EventHandler(handler.function)}

    await handler.function([])
    assert calls == ["normal_event_handler", "callable_attr"]
Exemple #4
0
 async def simple_stateful_element(self, tag):
     return idom.vdom(tag)
Exemple #5
0
 async def simple_param_element(self, tag):
     return idom.vdom(tag)
Exemple #6
0
def test_vdom_attribute_arguments_come_before_children():
    with pytest.raises(ValueError):
        idom.vdom("div", ["c1", "c2"], {"attr": 1})
Exemple #7
0
import idom
from idom.core.vdom import make_vdom_constructor

fake_events = idom.Events()


@fake_events.on("Click")
async def handler(event):
    pass


@pytest.mark.parametrize(
    "actual, expected",
    [
        (
            idom.vdom("div", [idom.vdom("div")]),
            {
                "tagName": "div",
                "children": [{
                    "tagName": "div"
                }]
            },
        ),
        (
            idom.vdom("div", {"style": {
                "backgroundColor": "red"
            }}),
            {
                "tagName": "div",
                "attributes": {
                    "style": {
Exemple #8
0
import idom
from idom.core.vdom import make_vdom_constructor, component

fake_events = idom.Events()


@fake_events.on("Click")
async def handler(event):
    pass


@pytest.mark.parametrize(
    "actual, expected",
    [
        (
            idom.vdom("div", [idom.vdom("div")]),
            {
                "tagName": "div",
                "children": [{
                    "tagName": "div"
                }]
            },
        ),
        (
            idom.vdom("div", {"style": {
                "backgroundColor": "red"
            }}),
            {
                "tagName": "div",
                "attributes": {
                    "style": {
Exemple #9
0
 async def SimpleElement(self, tag):
     return idom.vdom(tag)
Exemple #10
0
 def SimpleParamComponent(tag):
     return idom.vdom(tag)
Exemple #11
0
import idom
from idom.core.vdom import component, make_vdom_constructor

fake_events = idom.Events()


@fake_events.on("Click")
async def handler(event):
    pass


@pytest.mark.parametrize(
    "actual, expected",
    [
        (
            idom.vdom("div", [idom.vdom("div")]),
            {
                "tagName": "div",
                "children": [{
                    "tagName": "div"
                }]
            },
        ),
        (
            idom.vdom("div", {"style": {
                "backgroundColor": "red"
            }}),
            {
                "tagName": "div",
                "attributes": {
                    "style": {
Exemple #12
0
 def SimpleComponent():
     tag, set_state_hook.current = idom.hooks.use_state("div")
     return idom.vdom(tag)
Exemple #13
0
 def MyComponent():
     return idom.vdom("div")
Exemple #14
0
def test_debug_log_cannot_verify_keypath_for_genereators(caplog):
    idom.vdom("div", (1 for i in range(10)))
    assert len(caplog.records) == 1
    assert caplog.records[0].message.startswith(
        "Did not verify key-path integrity of children in generator")
    caplog.records.clear()
Exemple #15
0
def test_debug_log_if_children_in_attributes(caplog):
    idom.vdom("div", {"children": ["hello"]})
    assert len(caplog.records) == 1
    assert caplog.records[0].message.startswith(
        "Reserved key 'children' found in attributes")
    caplog.records.clear()
Exemple #16
0
        (False, VdomDict()),
        (True, {
            "tagName": ""
        }),
        (True, VdomDict(tagName="")),
    ],
)
def test_is_vdom(result, value):
    assert is_vdom(value) == result


@pytest.mark.parametrize(
    "actual, expected",
    [
        (
            idom.vdom("div", [idom.vdom("div")]),
            {
                "tagName": "div",
                "children": [{
                    "tagName": "div"
                }]
            },
        ),
        (
            idom.vdom("div", {"style": {
                "backgroundColor": "red"
            }}),
            {
                "tagName": "div",
                "attributes": {
                    "style": {