Files
MyFastHtml/tests/controls/test_helpers.py
2025-10-31 21:49:12 +01:00

49 lines
1.2 KiB
Python

import pytest
from fasthtml.components import *
from fasthtml.fastapp import fast_app
from myfasthtml.controls.helpers import mk
from myfasthtml.core.commands import Command
from myfasthtml.test.matcher import matches
from myfasthtml.test.testclient import MyTestClient
@pytest.fixture()
def user():
test_app, rt = fast_app(default_hdrs=False)
user = MyTestClient(test_app)
return user
@pytest.fixture()
def rt(user):
return user.app.route
def test_i_can_mk_button():
button = mk.button('button')
expected = Button('button')
assert matches(button, expected)
def test_i_can_mk_button_with_attrs():
button = mk.button('button', id="button_id", class_="button_class")
expected = Button('button', id="button_id", class_="button_class")
assert matches(button, expected)
def test_i_can_mk_button_with_command(user, rt):
def new_value(value): return value
command = Command('test', 'TestingCommand', new_value, "this is my new value")
@rt('/')
def get(): return mk.button('button', command)
user.open("/")
user.should_see("button")
user.find_element("button").click()
user.should_see("this is my new value")