Skip to content

Commit

Permalink
add settings page tests
Browse files Browse the repository at this point in the history
display settings tests
  • Loading branch information
odudex committed Jun 30, 2024
1 parent f80e79b commit 834ac08
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/krux/pages/settings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
152 changes: 108 additions & 44 deletions tests/pages/test_settings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -24,15 +24,16 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer):
index_next = (index_pt + 1) % (len(tlist))

cases = [
( # 0
( # 0 - Change Network
(
# Default Wallet
BUTTON_ENTER,
# Go to Network
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,
Expand All @@ -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,
Expand All @@ -64,85 +63,79 @@ 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,
BUTTON_ENTER,
),
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:
Expand All @@ -151,14 +144,44 @@ 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()

assert ctx.input.wait_for_button.call_count == len(case[0])
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 834ac08

Please sign in to comment.