mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add test for scroll_to_center method.
This commit is contained in:
40
tests/snapshot_tests/snapshot_apps/scroll_to_center.py
Normal file
40
tests/snapshot_tests/snapshot_apps/scroll_to_center.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import HorizontalScroll, VerticalScroll
|
||||||
|
from textual.widgets import Label
|
||||||
|
|
||||||
|
|
||||||
|
class MyApp(App[None]):
|
||||||
|
CSS = """
|
||||||
|
VerticalScroll, HorizontalScroll {
|
||||||
|
border: round $primary;
|
||||||
|
}
|
||||||
|
#vertical {
|
||||||
|
height: 21;
|
||||||
|
}
|
||||||
|
HorizontalScroll {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
with VerticalScroll():
|
||||||
|
yield Label(("SPAM\n" * 25)[:-1])
|
||||||
|
with VerticalScroll():
|
||||||
|
yield Label(("SPAM\n" * 53)[:-1])
|
||||||
|
with VerticalScroll(id="vertical"):
|
||||||
|
yield Label(("SPAM\n" * 78)[:-1])
|
||||||
|
with HorizontalScroll():
|
||||||
|
yield Label(("v\n" * 17)[:-1])
|
||||||
|
yield Label("@" * 302)
|
||||||
|
yield Label("[red]>>bullseye<<[/red]", id="bullseye")
|
||||||
|
yield Label("@" * 99)
|
||||||
|
yield Label(("SPAM\n" * 49)[:-1])
|
||||||
|
yield Label(("SPAM\n" * 51)[:-1])
|
||||||
|
yield Label(("SPAM\n" * 59)[:-1])
|
||||||
|
|
||||||
|
def key_s(self) -> None:
|
||||||
|
self.query_one("#bullseye").scroll_to_center()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
MyApp().run()
|
||||||
@@ -406,3 +406,7 @@ def test_fr_margins(snap_compare):
|
|||||||
def test_scroll_visible(snap_compare):
|
def test_scroll_visible(snap_compare):
|
||||||
# https://github.com/Textualize/textual/issues/2181
|
# https://github.com/Textualize/textual/issues/2181
|
||||||
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_visible.py", press=["t"])
|
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_visible.py", press=["t"])
|
||||||
|
|
||||||
|
|
||||||
|
def test_scroll_to_center(snap_compare):
|
||||||
|
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_to_center.py", press=["s"])
|
||||||
|
|||||||
Reference in New Issue
Block a user