mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add tests for Horizontal/Vertical(Scroll) containers.
This commit is contained in:
File diff suppressed because one or more lines are too long
56
tests/snapshot_tests/snapshot_apps/layout_containers.py
Normal file
56
tests/snapshot_tests/snapshot_apps/layout_containers.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
App to test layout containers.
|
||||
"""
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import (
|
||||
Grid,
|
||||
Horizontal,
|
||||
HorizontalScroll,
|
||||
Vertical,
|
||||
VerticalScroll,
|
||||
)
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Button, Input, Label
|
||||
|
||||
|
||||
def sub_compose() -> Iterable[Widget]:
|
||||
yield Button.success("Accept")
|
||||
yield Button.error("Decline")
|
||||
yield Input()
|
||||
yield Label("\n\n".join([str(n * 1_000_000) for n in range(10)]))
|
||||
|
||||
|
||||
class MyApp(App[None]):
|
||||
CSS = """
|
||||
Grid {
|
||||
grid-size: 2 2;
|
||||
grid-rows: 1fr;
|
||||
grid-columns: 1fr;
|
||||
}
|
||||
Grid > Widget {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
Input {
|
||||
width: 80;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Grid():
|
||||
with Horizontal():
|
||||
yield from sub_compose()
|
||||
with HorizontalScroll():
|
||||
yield from sub_compose()
|
||||
with Vertical():
|
||||
yield from sub_compose()
|
||||
with VerticalScroll():
|
||||
yield from sub_compose()
|
||||
|
||||
|
||||
app = MyApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
@@ -48,6 +48,10 @@ def test_dock_layout_sidebar(snap_compare):
|
||||
assert snap_compare(LAYOUT_EXAMPLES_DIR / "dock_layout2_sidebar.py")
|
||||
|
||||
|
||||
def test_layout_containers(snap_compare):
|
||||
assert snap_compare(SNAPSHOT_APPS_DIR / "layout_containers.py")
|
||||
|
||||
|
||||
# --- Widgets - rendering and basic interactions ---
|
||||
# Each widget should have a canonical example that is display in the docs.
|
||||
# When adding a new widget, ideally we should also create a snapshot test
|
||||
@@ -170,9 +174,11 @@ def test_content_switcher_example_initial(snap_compare):
|
||||
|
||||
|
||||
def test_content_switcher_example_switch(snap_compare):
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "content_switcher.py", press=[
|
||||
"tab", "tab", "enter", "wait:500"
|
||||
], terminal_size=(50, 50))
|
||||
assert snap_compare(
|
||||
WIDGET_EXAMPLES_DIR / "content_switcher.py",
|
||||
press=["tab", "tab", "enter", "wait:500"],
|
||||
terminal_size=(50, 50),
|
||||
)
|
||||
|
||||
|
||||
# --- CSS properties ---
|
||||
@@ -234,6 +240,7 @@ def test_programmatic_scrollbar_gutter_change(snap_compare):
|
||||
# --- CLI Preview Apps ---
|
||||
# For our CLI previews e.g. `textual easing`, `textual colors` etc, we have snapshots
|
||||
|
||||
|
||||
def test_borders_preview(snap_compare):
|
||||
assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "enter"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user