From 84ddd092230ce7c9d38c8e4766afc5b1ce375ea5 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Sun, 7 May 2023 20:26:12 +0100 Subject: [PATCH] Add extra snapshit tests This tests the three main ways of making an option list, and ensures they all turn out the same. --- .../__snapshots__/test_snapshots.ambr | 158 ++++++++++++++++++ .../snapshot_apps/option_list.py | 45 +++++ tests/snapshot_tests/test_snapshots.py | 2 + 3 files changed, 205 insertions(+) create mode 100644 tests/snapshot_tests/snapshot_apps/option_list.py diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index b69b5dfe4..5b06d31c0 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -19195,6 +19195,164 @@ ''' # --- +# name: test_option_list_build + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OptionListApp + + + + + + + + + + OneOneOne + TwoTwoTwo + ──────────────────────────────────────────────────────────────────────────────── + ThreeThreeThree + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_order_independence ''' diff --git a/tests/snapshot_tests/snapshot_apps/option_list.py b/tests/snapshot_tests/snapshot_apps/option_list.py new file mode 100644 index 000000000..36e4691dd --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/option_list.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from rich.text import Text + +from textual.app import App, ComposeResult +from textual.containers import Horizontal +from textual.widgets import OptionList +from textual.widgets.option_list import Option + + +class OptionListApp(App[None]): + + def compose( self ) -> ComposeResult: + with Horizontal(): + yield OptionList( + "One", + Option("Two"), + None, + Text.from_markup("[red]Three[/]") + ) + yield OptionList(id="later-individual") + yield OptionList(id="later-at-once") + + def on_mount(self) -> None: + options: list[None | str | Text | Option] = [ + "One", + Option("Two"), + None, + Text.from_markup("[red]Three[/]"), + ] + option_list = self.query_one("#later-individual", OptionList) + for option in options: + option_list.add_option(option) + option_list.highlighted = 0 + option_list = self.query_one("#later-at-once", OptionList) + option_list.add_options([ + "One", + Option("Two"), + None, + Text.from_markup("[red]Three[/]"), + ]) + option_list.highlighted = 0 + +if __name__ == "__main__": + OptionListApp().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index c9aee9636..fde61ae64 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -203,6 +203,8 @@ def test_option_list(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_options.py") assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py") +def test_option_list_build(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "option_list.py") def test_progress_bar_indeterminate(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "progress_bar_isolated_.py", press=["f"])