Files

161 lines
5.3 KiB
Python
Raw Permalink Normal View History

2025-11-15 22:06:12 +01:00
"""
2026-01-23 21:37:53 +01:00
Test MposKeyboard animation support (show/hide with WidgetAnimator).
2025-11-15 22:06:12 +01:00
2025-11-15 23:43:12 +01:00
This test reproduces the bug where MposKeyboard is missing methods
2026-01-23 21:37:53 +01:00
required by WidgetAnimator.smooth_show() and smooth_hide().
2025-11-15 22:06:12 +01:00
Usage:
Desktop: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py
2025-11-16 00:29:22 +01:00
Device: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py --ondevice
2025-11-15 22:06:12 +01:00
"""
import unittest
import lvgl as lv
2025-11-29 14:59:14 +01:00
import time
2026-01-23 21:37:53 +01:00
from mpos.ui.widget_animator import WidgetAnimator
from mpos.ui.testing import KeyboardTestCase
2025-11-15 22:06:12 +01:00
2025-12-19 11:13:40 +01:00
class TestKeyboardAnimation(KeyboardTestCase):
2025-11-15 23:43:12 +01:00
"""Test MposKeyboard compatibility with animation system."""
2025-11-15 22:06:12 +01:00
def test_keyboard_has_set_style_opa(self):
"""
2025-11-15 23:43:12 +01:00
Test that MposKeyboard has set_style_opa method.
2025-11-15 22:06:12 +01:00
2026-01-23 21:37:53 +01:00
This method is required by WidgetAnimator for fade animations.
2025-11-15 22:06:12 +01:00
"""
2025-11-15 23:43:12 +01:00
print("Testing that MposKeyboard has set_style_opa...")
2025-11-15 22:06:12 +01:00
2025-12-19 11:13:40 +01:00
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
2025-11-15 22:06:12 +01:00
# Verify method exists
self.assertTrue(
2025-12-19 11:13:40 +01:00
hasattr(self.keyboard, 'set_style_opa'),
2025-11-15 23:43:12 +01:00
"MposKeyboard missing set_style_opa method"
2025-11-15 22:06:12 +01:00
)
self.assertTrue(
2025-12-19 11:13:40 +01:00
callable(getattr(self.keyboard, 'set_style_opa')),
2025-11-15 23:43:12 +01:00
"MposKeyboard.set_style_opa is not callable"
2025-11-15 22:06:12 +01:00
)
# Try calling it (should not raise AttributeError)
try:
2025-12-19 11:13:40 +01:00
self.keyboard.set_style_opa(128, 0)
2025-11-15 22:06:12 +01:00
print("set_style_opa called successfully")
except AttributeError as e:
self.fail(f"set_style_opa raised AttributeError: {e}")
print("=== set_style_opa test PASSED ===")
def test_keyboard_smooth_show(self):
"""
2025-11-15 23:43:12 +01:00
Test that MposKeyboard can be shown with smooth_show animation.
2025-11-15 22:06:12 +01:00
This reproduces the actual user interaction in QuasiNametag.
"""
print("Testing smooth_show animation...")
2025-12-19 11:13:40 +01:00
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
2025-11-15 22:06:12 +01:00
# This should work without raising AttributeError
try:
2026-01-23 21:37:53 +01:00
WidgetAnimator.smooth_show(self.keyboard)
2025-12-19 11:13:40 +01:00
self.wait_for_render(100)
2025-11-15 22:06:12 +01:00
print("smooth_show called successfully")
except AttributeError as e:
self.fail(f"smooth_show raised AttributeError: {e}\n"
2025-11-15 23:43:12 +01:00
"This is the bug - MposKeyboard missing animation methods")
2025-11-15 22:06:12 +01:00
# Verify keyboard is no longer hidden
self.assertFalse(
2025-12-19 11:13:40 +01:00
self.keyboard.has_flag(lv.obj.FLAG.HIDDEN),
2025-11-15 22:06:12 +01:00
"Keyboard should not be hidden after smooth_show"
)
print("=== smooth_show test PASSED ===")
def test_keyboard_smooth_hide(self):
"""
2025-11-15 23:43:12 +01:00
Test that MposKeyboard can be hidden with smooth_hide animation.
2025-11-15 22:06:12 +01:00
This reproduces the hide behavior in QuasiNametag.
"""
print("Testing smooth_hide animation...")
2025-12-19 11:13:40 +01:00
self.create_keyboard_scene()
2025-11-15 22:06:12 +01:00
# Start visible
2025-12-19 11:13:40 +01:00
self.keyboard.remove_flag(lv.obj.FLAG.HIDDEN)
2025-11-15 22:06:12 +01:00
# This should work without raising AttributeError
try:
2026-01-23 21:37:53 +01:00
WidgetAnimator.smooth_hide(self.keyboard)
2025-11-15 22:06:12 +01:00
print("smooth_hide called successfully")
except AttributeError as e:
self.fail(f"smooth_hide raised AttributeError: {e}\n"
2025-11-15 23:43:12 +01:00
"This is the bug - MposKeyboard missing animation methods")
2025-11-15 22:06:12 +01:00
print("=== smooth_hide test PASSED ===")
def test_keyboard_show_hide_cycle(self):
"""
Test full show/hide animation cycle.
This mimics the actual user flow:
1. Click textarea -> show keyboard
2. Press Enter/Cancel -> hide keyboard
"""
print("Testing full show/hide cycle...")
2025-12-19 11:13:40 +01:00
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
2025-11-15 22:06:12 +01:00
# Initial state: hidden
2025-12-19 11:13:40 +01:00
self.assertTrue(self.keyboard.has_flag(lv.obj.FLAG.HIDDEN))
2025-11-15 22:06:12 +01:00
# Show keyboard (simulates textarea click)
try:
2026-01-23 21:37:53 +01:00
WidgetAnimator.smooth_show(self.keyboard)
2025-12-19 11:13:40 +01:00
self.wait_for_render(100)
2025-11-15 22:06:12 +01:00
except AttributeError as e:
self.fail(f"Failed during smooth_show: {e}")
# Should be visible now
2025-12-19 11:13:40 +01:00
self.assertFalse(self.keyboard.has_flag(lv.obj.FLAG.HIDDEN))
2025-11-15 22:06:12 +01:00
# Hide keyboard (simulates pressing Enter)
try:
2026-01-23 21:37:53 +01:00
WidgetAnimator.smooth_hide(self.keyboard)
2025-12-19 11:13:40 +01:00
self.wait_for_render(100)
2025-11-15 22:06:12 +01:00
except AttributeError as e:
self.fail(f"Failed during smooth_hide: {e}")
print("=== Full cycle test PASSED ===")
def test_keyboard_has_get_y_and_set_y(self):
"""
2025-11-15 23:43:12 +01:00
Test that MposKeyboard has get_y and set_y methods.
2025-11-15 22:06:12 +01:00
These are required for slide animations (though not currently used).
"""
print("Testing get_y and set_y methods...")
2025-12-19 11:13:40 +01:00
self.create_keyboard_scene()
2025-11-15 22:06:12 +01:00
# Verify methods exist
2025-12-19 11:13:40 +01:00
self.assertTrue(hasattr(self.keyboard, 'get_y'), "Missing get_y method")
self.assertTrue(hasattr(self.keyboard, 'set_y'), "Missing set_y method")
2025-11-15 22:06:12 +01:00
# Try using them
try:
2025-12-19 11:13:40 +01:00
y = self.keyboard.get_y()
self.keyboard.set_y(y + 10)
new_y = self.keyboard.get_y()
2025-11-15 22:06:12 +01:00
print(f"Position test: {y} -> {new_y}")
except AttributeError as e:
self.fail(f"Position methods raised AttributeError: {e}")
print("=== Position methods test PASSED ===")