Add tests for clicking on a link when markdown is from a string

Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
This commit is contained in:
Dave Pearson
2023-09-07 16:43:09 +01:00
parent 3b0e86bfef
commit ea832b8a9a

View File

@@ -7,7 +7,7 @@ from textual.geometry import Offset
from textual.widgets import Markdown, MarkdownViewer
class MarkdownViewerApp(App[None]):
class MarkdownFileViewerApp(App[None]):
def compose(self) -> ComposeResult:
yield MarkdownViewer()
@@ -17,9 +17,29 @@ class MarkdownViewerApp(App[None]):
@pytest.mark.parametrize("link", [0, 1, 2])
async def test_markdown_viewer_anchor_link(link: int) -> None:
async def test_markdown_file_viewer_anchor_link(link: int) -> None:
"""Test https://github.com/Textualize/textual/issues/3094"""
async with MarkdownViewerApp().run_test() as pilot:
async with MarkdownFileViewerApp().run_test() as pilot:
# There's not really anything to test *for* here, but the lack of an
# exception is the win (before the fix this is testing it would have
# been FileNotFoundError).
await pilot.click(Markdown, Offset(2, link))
class MarkdownStringViewerApp(App[None]):
def compose(self) -> ComposeResult:
yield MarkdownViewer(Path(__file__).with_suffix(".md").read_text())
async def on_mount(self) -> None:
self.query_one(MarkdownViewer).show_table_of_contents = False
@pytest.mark.parametrize("link", [0, 1, 2])
async def test_markdown_string_viewer_anchor_link(link: int) -> None:
"""Test https://github.com/Textualize/textual/issues/3094
Also https://github.com/Textualize/textual/pull/3244#issuecomment-1710278718."""
async with MarkdownStringViewerApp().run_test() as pilot:
# There's not really anything to test *for* here, but the lack of an
# exception is the win (before the fix this is testing it would have
# been FileNotFoundError).