From bfdaf02f667ff2fddf50cf1272ce56bcaf336a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Thu, 18 May 2023 14:26:32 +0100 Subject: [PATCH] Add snapshot test. --- tests/input/test_suggestions.py | 0 .../__snapshots__/test_snapshots.ambr | 160 ++++++++++++++++++ tests/snapshot_tests/conftest.py | 2 +- .../snapshot_apps/input_suggestions.py | 22 +++ tests/snapshot_tests/test_snapshots.py | 8 +- 5 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 tests/input/test_suggestions.py create mode 100644 tests/snapshot_tests/snapshot_apps/input_suggestions.py diff --git a/tests/input/test_suggestions.py b/tests/input/test_suggestions.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 9e342171a..260107313 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -16632,6 +16632,166 @@ ''' # --- +# name: test_input_suggestions + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FruitsApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + strawberry + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_key_display ''' diff --git a/tests/snapshot_tests/conftest.py b/tests/snapshot_tests/conftest.py index d45cd87ac..236e527b2 100644 --- a/tests/snapshot_tests/conftest.py +++ b/tests/snapshot_tests/conftest.py @@ -40,7 +40,7 @@ def snap_compare( def compare( app_path: str | PurePath, - press: Iterable[str] = ("_",), + press: Iterable[str] = (), terminal_size: tuple[int, int] = (80, 24), run_before: Callable[[Pilot], Awaitable[None] | None] | None = None, ) -> bool: diff --git a/tests/snapshot_tests/snapshot_apps/input_suggestions.py b/tests/snapshot_tests/snapshot_apps/input_suggestions.py new file mode 100644 index 000000000..1ddc4ba42 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/input_suggestions.py @@ -0,0 +1,22 @@ +from textual.app import App, ComposeResult +from textual.widgets import Input + + +fruits = ["apple", "pear", "mango", "peach", "strawberry", "blueberry", "banana"] + + +class FruitsApp(App[None]): + CSS = """ + Input > .input--suggestion { + color: red; + text-style: italic; + } + """ + + def compose(self) -> ComposeResult: + yield Input("straw", suggestions=fruits) + + +if __name__ == "__main__": + app = FruitsApp() + app.run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index bdedbced3..0c8fb5abb 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -84,6 +84,10 @@ def test_input_and_focus(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "input.py", press=press) +def test_input_suggestions(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "input_suggestions.py", press=[]) + + def test_buttons_render(snap_compare): # Testing button rendering. We press tab to focus the first button too. assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab"]) @@ -463,7 +467,9 @@ def test_dock_scroll2(snap_compare): def test_dock_scroll_off_by_one(snap_compare): # https://github.com/Textualize/textual/issues/2525 assert snap_compare( - SNAPSHOT_APPS_DIR / "dock_scroll_off_by_one.py", terminal_size=(80, 25) + SNAPSHOT_APPS_DIR / "dock_scroll_off_by_one.py", + terminal_size=(80, 25), + press=["_"], )