mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-17 07:12:08 +08:00
47ca2c9381
* stash * widgets animate out * Revert "stash" This reverts commit eac3493509cff6f2c64111d803c7fef21a1aa2dd. * abstract * works also * works also * support pop_widget * only animate top * callback in request pop * tune it * fix * fix * try this * Revert "try this" This reverts commit 191373a1b35917ee3a361afe73b16eeb60d0a20e. * debug * debug * clean up * simple test * clean up * clean up * clean up * clean up * clean up * clean up * clkean up * re sort * fine * yes
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
import pytest
|
|
from openpilot.system.ui.lib.application import gui_app
|
|
|
|
|
|
class Widget:
|
|
def __init__(self):
|
|
self.enabled, self.shown, self.hidden = True, False, False
|
|
|
|
def set_enabled(self, e): self.enabled = e
|
|
def show_event(self): self.shown = True
|
|
def hide_event(self): self.hidden = True
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def clean_stack():
|
|
gui_app._nav_stack = []
|
|
yield
|
|
gui_app._nav_stack = []
|
|
|
|
|
|
def test_push():
|
|
a, b = Widget(), Widget()
|
|
gui_app.push_widget(a)
|
|
gui_app.push_widget(b)
|
|
assert not a.enabled and not a.hidden
|
|
assert b.enabled and b.shown
|
|
|
|
|
|
def test_pop_re_enables():
|
|
widgets = [Widget() for _ in range(4)]
|
|
for w in widgets:
|
|
gui_app.push_widget(w)
|
|
assert all(not w.enabled for w in widgets[:-1])
|
|
gui_app.pop_widget()
|
|
assert widgets[-2].enabled
|
|
|
|
|
|
@pytest.mark.parametrize("pop_fn", [gui_app.pop_widgets_to, gui_app.request_pop_widgets_to])
|
|
def test_pop_widgets_to(pop_fn):
|
|
widgets = [Widget() for _ in range(4)]
|
|
for w in widgets:
|
|
gui_app.push_widget(w)
|
|
|
|
root = widgets[0]
|
|
pop_fn(root)
|
|
|
|
assert gui_app._nav_stack == [root]
|
|
assert root.enabled and not root.hidden
|
|
for w in widgets[1:]:
|
|
assert w.enabled and w.hidden and w.shown
|