""" Comprehensive binding tests for all bindable FastHTML components. This test suite covers: - Input (text) - already tested - Checkbox - already tested - Textarea - Select (single) - Select (multiple) - Range (slider) - Radio buttons - Button - Input with Datalist (combobox) """ from dataclasses import dataclass from fasthtml.components import ( Label, Button ) from myfasthtml.controls.helpers import mk from myfasthtml.core.bindings import Binding @dataclass class Data: value: str = "hello world" @dataclass class NumericData: value: int = 50 @dataclass class BoolData: value: bool = True @dataclass class ListData: value: list = None def __post_init__(self): if self.value is None: self.value = [] class TestBindingButton: """Tests for binding Button components.""" def test_i_can_click_button_with_binding(self, user, rt): """ Clicking a button with HTMX should trigger binding updates. """ @rt("/") def index(): data = Data("initial") button_elt = Button("Click me", hx_post="/update", hx_vals='{"action": "clicked"}') label_elt = Label() mk.manage_binding(button_elt, Binding(data)) mk.manage_binding(label_elt, Binding(data)) return button_elt, label_elt @rt("/update") def update(action: str): data = Data("button clicked") label_elt = Label() mk.manage_binding(label_elt, Binding(data)) return label_elt user.open("/") user.should_see("initial") testable_button = user.find_element("button") testable_button.click() user.should_see("button clicked") def test_button_without_htmx_does_nothing(self, user, rt): """ Button without HTMX should not trigger updates. """ @rt("/") def index(): data = Data("initial") button_elt = Button("Plain button") # No HTMX label_elt = Label() mk.manage_binding(button_elt, Binding(data)) mk.manage_binding(label_elt, Binding(data)) return button_elt, label_elt user.open("/") user.should_see("initial") testable_button = user.find_element("button") result = testable_button.click() assert result is None # No HTMX, no response