@@ -219,3 +219,92 @@ def _click(i="a", seq=None):
219219 assert index == menu .back_index
220220 assert status == MENU_EXIT
221221 assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
222+
223+
224+ def test_fast_forward (mocker , m5stickv ):
225+ from krux .input import PRESSED , FAST_FORWARD , FAST_BACKWARD
226+ from krux .pages import Menu
227+
228+ ctx = mock_context (mocker )
229+ ctx .input .page_value = mocker .MagicMock (return_value = PRESSED )
230+ menu = Menu (ctx , [])
231+
232+ assert menu ._get_btn_input () == FAST_FORWARD
233+
234+ ctx .input .page_value = mocker .MagicMock (return_value = None )
235+
236+ ctx .input .page_prev_value = mocker .MagicMock (return_value = PRESSED )
237+
238+ assert menu ._get_btn_input () == FAST_BACKWARD
239+
240+
241+ def test_swipe_up (mocker , amigo ):
242+ from krux .pages import Menu , MENU_EXIT , MENU_CONTINUE
243+ from krux .input import SWIPE_UP
244+
245+ ctx = mock_context (mocker )
246+ menu = Menu (ctx , [])
247+
248+ def swipe_fnc ():
249+ return (1 , MENU_EXIT )
250+
251+ assert menu ._process_swipe_up (0 , swipe_up_fnc = swipe_fnc ) == (1 , MENU_EXIT )
252+ assert menu ._process_swipe_down (0 , swipe_down_fnc = swipe_fnc ) == (1 , MENU_EXIT )
253+
254+ BTN_SEQUENCE = [
255+ SWIPE_UP ,
256+ ]
257+ ctx .input .wait_for_button .side_effect = BTN_SEQUENCE
258+ index , status = menu .run_loop (swipe_up_fnc = swipe_fnc )
259+ assert index == 1
260+ assert status == MENU_EXIT
261+
262+ def swipe_fnc_continue ():
263+ return (2 , MENU_CONTINUE )
264+
265+ assert menu ._process_swipe_up (0 , swipe_up_fnc = swipe_fnc_continue ) == 0
266+ assert menu ._process_swipe_down (0 , swipe_down_fnc = swipe_fnc_continue ) == 0
267+
268+
269+ def test_start_from (mocker , m5stickv ):
270+ from krux .pages import Menu , MENU_EXIT , MENU_CONTINUE
271+ from krux .input import BUTTON_ENTER , BUTTON_PAGE_PREV
272+
273+ ctx = mock_context (mocker )
274+
275+ mock_fnc = mocker .MagicMock (return_value = MENU_CONTINUE )
276+ menu_items = [
277+ ("1" , mock_fnc ),
278+ ("2" , lambda : MENU_EXIT ),
279+ ]
280+ menu = Menu (ctx , menu_items )
281+ # test start menu clicking on index 1 that will exit
282+ index , status = menu .run_loop (start_from_index = 1 )
283+ assert index == 1
284+ assert status == MENU_EXIT
285+
286+ # test start menu clicking on index 0 that will NOT exit
287+ BTN_SEQUENCE = [BUTTON_PAGE_PREV ] + [BUTTON_ENTER ] # go to back # click back
288+ ctx .input .wait_for_button .side_effect = BTN_SEQUENCE
289+ index , status = menu .run_loop (start_from_index = 0 )
290+ assert index == menu .back_index
291+ assert status == MENU_EXIT
292+ mock_fnc .assert_called ()
293+ assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
294+
295+
296+ def test_disabled_entry (mocker , m5stickv ):
297+ from krux .pages import Menu , MENU_EXIT
298+ from krux .input import BUTTON_ENTER , BUTTON_PAGE
299+
300+ ctx = mock_context (mocker )
301+ menu_items = [("Disabled" , None )]
302+ BTN_SEQUENCE = (
303+ [BUTTON_ENTER ] + [BUTTON_PAGE ] + [BUTTON_ENTER ] # click disabled # click back
304+ )
305+ ctx .input .wait_for_button .side_effect = BTN_SEQUENCE
306+ menu = Menu (ctx , menu_items )
307+ index , status = menu .run_loop ()
308+ assert index == menu .back_index
309+ assert status == MENU_EXIT
310+ assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
0 commit comments