Improve search select

This commit is contained in:
2026-06-07 09:01:18 +02:00
parent afc16aabbb
commit a6384fc003
4 changed files with 109 additions and 205 deletions
+14 -1
View File
@@ -63,9 +63,10 @@ class SearchSelectComponentTest(unittest.TestCase):
self.assertIn('data-search-url="/api/games/search"', html)
self.assertIn('data-multi="true"', html)
def test_selected_renders_pills_and_hidden_inputs(self):
def test_multi_selected_renders_pills_and_hidden_inputs(self):
html = SearchSelect(
name="games",
multi_select=True,
selected=[{"value": 7, "label": "Game A", "data": {"platform": "2"}}],
)
self.assertIn("data-pill", html)
@@ -75,6 +76,18 @@ class SearchSelectComponentTest(unittest.TestCase):
# name. The leading space avoids matching the container's data-name.
self.assertEqual(html.count(' name="games"'), 1)
def test_single_selected_has_no_pill_and_value_in_search_box(self):
html = SearchSelect(
name="games",
selected=[{"value": 7, "label": "Game A", "data": {"platform": "2"}}],
)
# single-select renders no pill — the label lives in the search box
self.assertNotIn("data-pill", html)
self.assertIn('value="Game A"', html)
# the value is still submitted via a lone hidden input
self.assertIn('<input type="hidden" name="games" value="7">', html)
self.assertEqual(html.count(' name="games"'), 1)
def test_search_box_has_no_name(self):
html = SearchSelect(name="games")
self.assertIn("data-ss-search", html)