diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 34042cbe235..803455113aa 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -20277,6 +20277,489 @@ ''' # --- +# name: test_option_list_replace_prompt_from_single_line_to_single_line + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OptionListApp + + + + + + + + + + OptionListApp + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + 1. Another single line + 2. Two + lines + 3. Three + lines + of text + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + + ''' +# --- +# name: test_option_list_replace_prompt_from_single_line_to_two_lines + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OptionListApp + + + + + + + + + + OptionListApp + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + 1. Two + lines + 2. Two + lines + 3. Three + lines + of text + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + ''' +# --- +# name: test_option_list_replace_prompt_from_two_lines_to_three_lines + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OptionListApp + + + + + + + + + + OptionListApp + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + 1. Single line + 1. Three + lines + of text + 3. Three + lines + of text + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_option_list_strings ''' diff --git a/tests/snapshot_tests/snapshot_apps/option_list_multiline_options.py b/tests/snapshot_tests/snapshot_apps/option_list_multiline_options.py new file mode 100644 index 00000000000..fe7e4bcf6f5 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/option_list_multiline_options.py @@ -0,0 +1,32 @@ +from __future__ import annotations + + +from textual.app import App, ComposeResult +from textual.widgets import OptionList, Header, Footer +from textual.widgets.option_list import Option + + +class OptionListApp(App[None]): + + def compose(self) -> ComposeResult: + yield Header() + yield OptionList( + Option("1. Single line", id="one"), + Option("2. Two\nlines", id="two"), + Option("3. Three\nlines\nof text", id="three"), + ) + + yield Footer() + + def key_1(self): + self.query_one(OptionList).replace_option_prompt_at_index(0, "1. Another single line") + + def key_2(self): + self.query_one(OptionList).replace_option_prompt_at_index(0, "1. Two\nlines") + + def key_3(self): + self.query_one(OptionList).replace_option_prompt_at_index(1, "1. Three\nlines\nof text") + + +if __name__ == "__main__": + OptionListApp().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 817eb64cf15..5c2d07b24e2 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -238,6 +238,18 @@ def test_option_list_build(snap_compare): assert snap_compare(SNAPSHOT_APPS_DIR / "option_list.py") +def test_option_list_replace_prompt_from_single_line_to_single_line(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "option_list_multiline_options.py", press=["1"]) + + +def test_option_list_replace_prompt_from_single_line_to_two_lines(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "option_list_multiline_options.py", press=["2"]) + + +def test_option_list_replace_prompt_from_two_lines_to_three_lines(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "option_list_multiline_options.py", press=["3"]) + + def test_progress_bar_indeterminate(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "progress_bar_isolated_.py", press=["f"])