-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_graphical_keyboard_animation.py
More file actions
174 lines (135 loc) · 5.87 KB
/
test_graphical_keyboard_animation.py
File metadata and controls
174 lines (135 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""
Test MposKeyboard animation support (show/hide with WidgetAnimator).
This test reproduces the bug where MposKeyboard is missing methods
required by WidgetAnimator.smooth_show() and smooth_hide().
Usage:
Desktop: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py
Device: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py --ondevice
"""
import unittest
import lvgl as lv
import time
from mpos.ui.widget_animator import WidgetAnimator
from mpos.ui.testing import KeyboardTestCase
class TestKeyboardAnimation(KeyboardTestCase):
"""Test MposKeyboard compatibility with animation system."""
def _wait_for_keyboard_hidden_state(self, hidden, attempts=6, render_iterations=30):
for attempt in range(1, attempts + 1):
is_hidden = self.keyboard.has_flag(lv.obj.FLAG.HIDDEN)
print(f"Keyboard hidden check {attempt}/{attempts}: {is_hidden}")
if is_hidden == hidden:
return True
self.wait_for_render(render_iterations)
time.sleep(0.2)
return False
def test_keyboard_has_set_style_opa(self):
"""
Test that MposKeyboard has set_style_opa method.
This method is required by WidgetAnimator for fade animations.
"""
print("Testing that MposKeyboard has set_style_opa...")
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
# Verify method exists
self.assertTrue(
hasattr(self.keyboard, 'set_style_opa'),
"MposKeyboard missing set_style_opa method"
)
self.assertTrue(
callable(getattr(self.keyboard, 'set_style_opa')),
"MposKeyboard.set_style_opa is not callable"
)
# Try calling it (should not raise AttributeError)
try:
self.keyboard.set_style_opa(128, 0)
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):
"""
Test that MposKeyboard can be shown with smooth_show animation.
This reproduces the actual user interaction in QuasiNametag.
"""
print("Testing smooth_show animation...")
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
# This should work without raising AttributeError
try:
WidgetAnimator.smooth_show(self.keyboard)
self.wait_for_render(100)
print("smooth_show called successfully")
except AttributeError as e:
self.fail(f"smooth_show raised AttributeError: {e}\n"
"This is the bug - MposKeyboard missing animation methods")
# Verify keyboard is no longer hidden
self.assertTrue(
self._wait_for_keyboard_hidden_state(False),
"Keyboard should not be hidden after smooth_show"
)
print("=== smooth_show test PASSED ===")
def test_keyboard_smooth_hide(self):
"""
Test that MposKeyboard can be hidden with smooth_hide animation.
This reproduces the hide behavior in QuasiNametag.
"""
print("Testing smooth_hide animation...")
self.create_keyboard_scene()
# Start visible
self.keyboard.remove_flag(lv.obj.FLAG.HIDDEN)
# This should work without raising AttributeError
try:
WidgetAnimator.smooth_hide(self.keyboard)
print("smooth_hide called successfully")
except AttributeError as e:
self.fail(f"smooth_hide raised AttributeError: {e}\n"
"This is the bug - MposKeyboard missing animation methods")
self.assertTrue(self._wait_for_keyboard_hidden_state(True))
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...")
self.create_keyboard_scene()
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
# Initial state: hidden
self.assertTrue(self.keyboard.has_flag(lv.obj.FLAG.HIDDEN))
# Show keyboard (simulates textarea click)
try:
WidgetAnimator.smooth_show(self.keyboard)
self.wait_for_render(100)
except AttributeError as e:
self.fail(f"Failed during smooth_show: {e}")
# Should be visible now
self.assertTrue(self._wait_for_keyboard_hidden_state(False))
# Hide keyboard (simulates pressing Enter)
try:
WidgetAnimator.smooth_hide(self.keyboard)
self.wait_for_render(100)
except AttributeError as e:
self.fail(f"Failed during smooth_hide: {e}")
self.assertTrue(self._wait_for_keyboard_hidden_state(True))
print("=== Full cycle test PASSED ===")
def test_keyboard_has_get_y_and_set_y(self):
"""
Test that MposKeyboard has get_y and set_y methods.
These are required for slide animations (though not currently used).
"""
print("Testing get_y and set_y methods...")
self.create_keyboard_scene()
# Verify methods exist
self.assertTrue(hasattr(self.keyboard, 'get_y'), "Missing get_y method")
self.assertTrue(hasattr(self.keyboard, 'set_y'), "Missing set_y method")
# Try using them
try:
y = self.keyboard.get_y()
self.keyboard.set_y(y + 10)
new_y = self.keyboard.get_y()
print(f"Position test: {y} -> {new_y}")
except AttributeError as e:
self.fail(f"Position methods raised AttributeError: {e}")
print("=== Position methods test PASSED ===")