mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add a test for clickable bar ranges
This commit is contained in:
@@ -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 tests.utilities.render import render
|
||||||
from textual.renderables.underline_bar import UnderlineBar
|
from textual.renderables.underline_bar import UnderlineBar
|
||||||
|
|
||||||
@@ -119,3 +125,19 @@ def test_custom_styles():
|
|||||||
f"{GREEN}╺{STOP}"
|
f"{GREEN}╺{STOP}"
|
||||||
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')"}
|
||||||
|
|||||||
Reference in New Issue
Block a user