Added first controls
This commit is contained in:
42
tests/testclient/test_finds.py
Normal file
42
tests/testclient/test_finds.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pytest
|
||||
from fasthtml.components import Div, Span
|
||||
|
||||
from myfasthtml.test.matcher import find
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ft, expected', [
|
||||
("hello", "hello"),
|
||||
(Div(id="id1"), Div(id="id1")),
|
||||
(Div(Span(id="span_id"), id="div_id1"), Div(Span(id="span_id"), id="div_id1")),
|
||||
(Div(id="id1", id2="id2"), Div(id="id1")),
|
||||
(Div(Div(id="id2"), id2="id1"), Div(id="id1")),
|
||||
])
|
||||
def test_i_can_find(ft, expected):
|
||||
assert find(expected, expected) == [expected]
|
||||
|
||||
|
||||
def test_find_element_by_id_in_a_list():
|
||||
a = Div(id="id1")
|
||||
b = Div(id="id2")
|
||||
c = Div(id="id3")
|
||||
|
||||
assert find([a, b, c], b) == [b]
|
||||
|
||||
|
||||
def test_i_can_find_sub_element():
|
||||
a = Div(id="id1")
|
||||
b = Div(a, id="id2")
|
||||
c = Div(b, id="id3")
|
||||
|
||||
assert find(c, a) == [a]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ft, expected', [
|
||||
(None, Div(id="id1")),
|
||||
(Span(id="id1"), Div(id="id1")),
|
||||
(Div(id2="id1"), Div(id="id1")),
|
||||
(Div(id="id2"), Div(id="id1")),
|
||||
])
|
||||
def test_i_cannot_find(ft, expected):
|
||||
with pytest.raises(AssertionError):
|
||||
find(expected, ft)
|
||||
Reference in New Issue
Block a user