From 834ac086a17a611e1b3b91da80dc9ff487906545 Mon Sep 17 00:00:00 2001 From: odudex Date: Sun, 30 Jun 2024 16:38:22 -0300 Subject: [PATCH] add settings page tests display settings tests --- src/krux/pages/settings_page.py | 1 + tests/pages/test_settings_page.py | 152 +++++++++++++++++++++--------- 2 files changed, 109 insertions(+), 44 deletions(-) diff --git a/src/krux/pages/settings_page.py b/src/krux/pages/settings_page.py index 8ab2d3d46..c85c9ca0f 100644 --- a/src/krux/pages/settings_page.py +++ b/src/krux/pages/settings_page.py @@ -382,6 +382,7 @@ def category_setting(self, settings_namespace, setting): self._settings_exit_check() self.ctx.display.clear() self.ctx.power_manager.reboot() + return MENU_EXIT # In case reboot fails else: # Restore previous theme setting.__set__(settings_namespace, starting_category) diff --git a/tests/pages/test_settings_page.py b/tests/pages/test_settings_page.py index 2715d66fb..29a19c532 100644 --- a/tests/pages/test_settings_page.py +++ b/tests/pages/test_settings_page.py @@ -3,14 +3,14 @@ from . import create_ctx from ..shared_mocks import mock_context from ..test_sd_card import mocker_sd_card_ok - - -@pytest.fixture -def mocker_printer(mocker): - mocker.patch("krux.printers.thermal.AdafruitPrinter", new=mocker.MagicMock()) +from .test_login import mocker_printer ################### Test menus +class RebootException(Exception): + """Exception to simulate rebooting the device.""" + + pass def test_settings_m5stickv(m5stickv, mocker, mocker_printer): @@ -24,7 +24,7 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): index_next = (index_pt + 1) % (len(tlist)) cases = [ - ( # 0 + ( # 0 - Change Network ( # Default Wallet BUTTON_ENTER, @@ -32,7 +32,8 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): BUTTON_PAGE, BUTTON_ENTER, # Change network - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), # Cycle through 2 options + BUTTON_PAGE_PREV, # Go back to the second option - testnet BUTTON_ENTER, # Leave Default Wallet BUTTON_PAGE, @@ -43,15 +44,13 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): ), lambda: Settings().wallet.network == "test", ), - ( # 1 + ( # 1 Printer Settings ( # Hardware - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Printer - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Thermal (printer) BUTTON_PAGE, @@ -64,26 +63,21 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): BUTTON_PAGE_PREV, BUTTON_ENTER, # Back to Printer - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Back to settings BUTTON_PAGE, BUTTON_ENTER, # Leave Settings - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, + *([BUTTON_PAGE_PREV] * 3), BUTTON_ENTER, ), lambda: Settings().hardware.printer.thermal.adafruit.baudrate == 19200, ), - ( # 2 + ( # 2 Language Settings ( # Language - BUTTON_PAGE, - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 3), BUTTON_ENTER, # Change Locale BUTTON_PAGE, @@ -91,58 +85,57 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): ), lambda: Settings().i18n.locale == tlist[index_next], ), - ( # 3 + ( # 3 Printer numeric settings ( # Hardware - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Printer - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Thermal (printer) BUTTON_PAGE, BUTTON_ENTER, # Paper Width - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Change width # Remove digit (become 38) - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, + *([BUTTON_PAGE_PREV] * 3), BUTTON_ENTER, # Add 9 BUTTON_PAGE_PREV, BUTTON_ENTER, # Go - BUTTON_PAGE, - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 3), BUTTON_ENTER, # Back to Thermal - BUTTON_PAGE, - BUTTON_PAGE, - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 4), BUTTON_ENTER, # Back to Printer - BUTTON_PAGE, - BUTTON_PAGE, + *([BUTTON_PAGE] * 2), BUTTON_ENTER, # Back to settings BUTTON_PAGE, BUTTON_ENTER, # Leave Settings - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, - BUTTON_PAGE_PREV, + *([BUTTON_PAGE_PREV] * 3), BUTTON_ENTER, ), lambda: Settings().hardware.printer.thermal.adafruit.paper_width == 389, ), + ( # 4 Change theme + ( + *([BUTTON_PAGE] * 6), # Move to "Appearance" + BUTTON_ENTER, # Enter "Appearance" + BUTTON_PAGE, # Move to "Theme" + BUTTON_ENTER, # Enter "Theme" + BUTTON_PAGE, # Change to "Light" + BUTTON_ENTER, # Confirm "Light" + BUTTON_ENTER, # Confirm reboot + ), + lambda: Settings().appearance.theme == "Light", + ), ] case_num = 0 for case in cases: @@ -151,7 +144,6 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): ctx = create_ctx(mocker, case[0]) settings_page = SettingsPage(ctx) - Settings().i18n.locale = "pt-BR" settings_page.settings() @@ -159,6 +151,37 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): assert case[1]() +@pytest.fixture(params=["m5stickv", "cube"]) +def bkl_control_devices(request): + return request.getfixturevalue(request.param) + + +def test_change_brightness(bkl_control_devices, mocker): + from krux.pages.settings_page import SettingsPage + from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV + from krux.krux_settings import Settings + + BTN_SEQUENCE = [ + *([BUTTON_PAGE] * 2), # Move to "Hardware" + BUTTON_ENTER, # Enter "Hardware" + BUTTON_PAGE, # Move to "Display" + BUTTON_ENTER, # Enter "Display" + BUTTON_PAGE, # Change "Brightness" + BUTTON_ENTER, # Enter "Brightness" + *([BUTTON_PAGE] * 2), # Move to "Back" + BUTTON_ENTER, # Confirm "Back" + *([BUTTON_PAGE_PREV] * 3), # Move to "Back" + BUTTON_ENTER, # Confirm "Back" + ] + ctx = create_ctx(mocker, BTN_SEQUENCE) + settings_page = SettingsPage(ctx) + previous_brightness = int(Settings().hardware.display.brightness) + settings_page.settings() + + assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE) + assert Settings().hardware.display.brightness == str(previous_brightness + 1) + + def test_settings_on_amigo_tft(amigo, mocker, mocker_printer): import krux from krux.pages.settings_page import SettingsPage @@ -278,6 +301,47 @@ def test_settings_on_amigo_tft(amigo, mocker, mocker_printer): assert case[2]() +def test_change_display_type_on_amigo(amigo, mocker): + from krux.pages.settings_page import SettingsPage + from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV + from krux.krux_settings import Settings, CategorySetting, NumberSetting + + BTN_SEQUENCE = [ + *([BUTTON_PAGE] * 2), # Move to "Hardware" + BUTTON_ENTER, # Enter "Hardware" + BUTTON_ENTER, # Enter "Display" + BUTTON_ENTER, # Enter "BGR colors" + BUTTON_PAGE, # Change "BGR Type" + BUTTON_ENTER, # Enter "BGR Type" + BUTTON_PAGE, # Go to "Flipped X ..." + BUTTON_ENTER, # Enter "Flipped X ..." + BUTTON_PAGE, # Change "Flipped X ..." + BUTTON_ENTER, # Enter "Flipped X ..." + BUTTON_PAGE, # Go to "Inverted Colors" + BUTTON_ENTER, # Enter "Inverted Colors" + BUTTON_PAGE, # Change "Inverted Colors" + BUTTON_ENTER, # Enter "Inverted Colors" + BUTTON_PAGE, # Go to "Type" + BUTTON_ENTER, # Enter "Type" + BUTTON_PAGE, # Change "Type" + BUTTON_ENTER, # Confirm "Warning" + BUTTON_PAGE_PREV, # Confirm new setting + BUTTON_ENTER, # Confirm "Type" + BUTTON_PAGE, # Move to "Back" + BUTTON_ENTER, # Confirm "Back" from display + BUTTON_PAGE_PREV, # Move to "Back" + BUTTON_ENTER, # Confirm "Back" from hardware + *([BUTTON_PAGE_PREV] * 3), # Move to "Back" + BUTTON_ENTER, # Confirm "Back" from settings + ] + ctx = create_ctx(mocker, BTN_SEQUENCE) + settings_page = SettingsPage(ctx) + settings_page.settings() + + assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE) + # assert Settings().hardware.display.bgr_type == "RGB" + + def test_encryption_pbkdf2_setting(m5stickv, mocker): from krux.pages.settings_page import SettingsPage from krux.krux_settings import Settings, EncryptionSettings