I can bind multi-select
This commit is contained in:
@@ -304,7 +304,109 @@ class TestBindingSelect:
|
||||
class TestBindingSelectMultiple:
|
||||
"""Tests for binding Select components with multiple selection."""
|
||||
|
||||
def test_i_can_bind_select_multiple(self, user, rt):
|
||||
def test_i_can_bind_select_multiple(self):
|
||||
data = Data("")
|
||||
select_elt = Select(
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
multiple=True
|
||||
)
|
||||
|
||||
binding = Binding(data)
|
||||
updated = mk.manage_binding(select_elt, binding)
|
||||
|
||||
expected = Select(
|
||||
AttributeForbidden("hx_swap_oob"),
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
id=AnyValue(),
|
||||
hx_post=f"{ROUTE_ROOT}{Routes.Bindings}",
|
||||
)
|
||||
assert matches(updated, expected)
|
||||
|
||||
def test_i_can_update_one_selection(self):
|
||||
data = Data("")
|
||||
select_elt = Select(
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
multiple=True
|
||||
)
|
||||
|
||||
binding = Binding(data)
|
||||
mk.manage_binding(select_elt, binding)
|
||||
|
||||
res = binding.update({"select_name": "option2"})
|
||||
|
||||
expected = Select(
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2", selected="true"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
id=AnyValue(),
|
||||
hx_post=f"{ROUTE_ROOT}{Routes.Bindings}",
|
||||
hx_swap_oob="true"
|
||||
)
|
||||
assert matches(res, [expected])
|
||||
|
||||
def test_i_can_update_multiple_selections(self):
|
||||
data = Data("")
|
||||
select_elt = Select(
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
multiple=True
|
||||
)
|
||||
|
||||
binding = Binding(data)
|
||||
mk.manage_binding(select_elt, binding)
|
||||
|
||||
res = binding.update({"select_name": ["option2", "option3"]})
|
||||
|
||||
expected = Select(
|
||||
Option(AttributeForbidden("selected"), "Option 1", value="option1"),
|
||||
Option("Option 2", value="option2", selected="true"),
|
||||
Option("Option 3", value="option3", selected="true"),
|
||||
name="select_name",
|
||||
id=AnyValue(),
|
||||
hx_post=f"{ROUTE_ROOT}{Routes.Bindings}",
|
||||
hx_swap_oob="true"
|
||||
)
|
||||
assert matches(res, [expected])
|
||||
|
||||
def test_i_can_update_unselect(self):
|
||||
data = Data(["option1", "option2", "option3"])
|
||||
select_elt = Select(
|
||||
Option("Option 1", value="option1", selected="true"),
|
||||
Option("Option 2", value="option2", selected="true"),
|
||||
Option("Option 3", value="option3", selected="true"),
|
||||
name="select_name",
|
||||
multiple=True
|
||||
)
|
||||
|
||||
binding = Binding(data)
|
||||
mk.manage_binding(select_elt, binding)
|
||||
|
||||
res = binding.update({})
|
||||
|
||||
expected = Select(
|
||||
Option(AttributeForbidden("selected"), "Option 1", value="option1"),
|
||||
Option(AttributeForbidden("selected"), "Option 2", value="option2"),
|
||||
Option(AttributeForbidden("selected"), "Option 3", value="option3"),
|
||||
name="select_name",
|
||||
id=AnyValue(),
|
||||
hx_post=f"{ROUTE_ROOT}{Routes.Bindings}",
|
||||
hx_swap_oob="true"
|
||||
)
|
||||
assert matches(res, [expected])
|
||||
|
||||
def test_i_can_bind_select_multiple_with_label(self, user, rt):
|
||||
"""
|
||||
Multiple select should bind with list data.
|
||||
Selecting multiple options should update the label.
|
||||
@@ -360,7 +462,7 @@ class TestBindingSelectMultiple:
|
||||
|
||||
testable_select = user.find_element("select")
|
||||
testable_select.deselect("option1")
|
||||
user.should_see("['option2']")
|
||||
user.should_see("option2")
|
||||
|
||||
|
||||
class TestBindingRange:
|
||||
|
||||
Reference in New Issue
Block a user