|
@@ -0,0 +1,52 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+from typing import Callable, Dict, Iterable, List
|
|
|
+from pytest import fixture, mark
|
|
|
+from app.parse_recipe import parse_recipe
|
|
|
+from app.data.QueryManager import QueryManager
|
|
|
+from app.rest import ALL_UNITS
|
|
|
+
|
|
|
+from app.widgets import SuggestionPopup
|
|
|
+from urwid import connect_signal
|
|
|
+from urwid import SimpleFocusListWalker
|
|
|
+from additional_urwid_widgets import IndicativeListBox
|
|
|
+
|
|
|
+@fixture
|
|
|
+def signals():
|
|
|
+ return []
|
|
|
+
|
|
|
+@fixture
|
|
|
+def signal(signals):
|
|
|
+ return lambda x, *a: signals.append(x)
|
|
|
+
|
|
|
+@fixture
|
|
|
+def tracker():
|
|
|
+ return dict()
|
|
|
+
|
|
|
+@fixture
|
|
|
+def options():
|
|
|
+ return ['a', 'b', 'c']
|
|
|
+
|
|
|
+@fixture
|
|
|
+def suggestion_popup(tracker, options, signal):
|
|
|
+ popup = SuggestionPopup('identifier', options, lambda x, y: tracker.update({x: y}))
|
|
|
+ popup._emit = signal
|
|
|
+ return popup
|
|
|
+
|
|
|
+@mark.parametrize('pos', [0, 1, 2])
|
|
|
+def test_suggestion_popup_choice(suggestion_popup: SuggestionPopup, tracker: Dict[str, str], options: List[str], pos: int):
|
|
|
+ while pos > 0:
|
|
|
+ pos -= 1
|
|
|
+ suggestion_popup.keypress((0,0), 'tab')
|
|
|
+ assert len(tracker.keys()) == 0
|
|
|
+ suggestion_popup.keypress((0,0), 'enter')
|
|
|
+ assert tracker['identifier'] == options[pos]
|
|
|
+
|
|
|
+def test_suggestion_popup_banish(suggestion_popup: SuggestionPopup, tracker: Dict[str, str], options: List[str], signals):
|
|
|
+ suggestion_popup.keypress((0,0), 'esc')
|
|
|
+ assert len(tracker.keys()) == 0
|
|
|
+ assert 'close' in signals
|