diff --git a/tests/renderables/test_underline_bar.py b/tests/renderables/test_underline_bar.py index 2d84da6f8..549b331e3 100644 --- a/tests/renderables/test_underline_bar.py +++ b/tests/renderables/test_underline_bar.py @@ -1,3 +1,9 @@ +from unittest.mock import create_autospec + +from rich.console import Console +from rich.console import ConsoleOptions +from rich.text import Text + from tests.utilities.render import render from textual.renderables.underline_bar import UnderlineBar @@ -119,3 +125,19 @@ def test_custom_styles(): f"{GREEN}╺{STOP}" f"{GREEN}━{STOP}" ) + + +def test_clickable_ranges(): + bar = UnderlineBar(highlight_range=(0, 1), width=6, clickable_ranges={"foo": (0, 2), "bar": (4, 5)}) + + console = create_autospec(Console) + options = create_autospec(ConsoleOptions) + text: Text = list(bar.__rich_console__(console, options))[0] + + start, end, style = text.spans[-2] + assert (start, end) == (0, 2) + assert style.meta == {'@click': "range_clicked('foo')"} + + start, end, style = text.spans[-1] + assert (start, end) == (4, 5) + assert style.meta == {'@click': "range_clicked('bar')"}