test_link_hover.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from typing import Generator
  2. import pytest
  3. from playwright.sync_api import Page, expect
  4. from reflex.testing import AppHarness
  5. def LinkApp():
  6. import reflex as rx
  7. app = rx.App()
  8. def index():
  9. return rx.vstack(
  10. rx.box(height="10em"), # spacer, so the link isn't hovered initially
  11. rx.link(
  12. "Click me",
  13. href="#",
  14. color="blue",
  15. _hover=rx.Style({"color": "red"}),
  16. ),
  17. )
  18. app.add_page(index, "/")
  19. @pytest.fixture()
  20. def link_app(tmp_path_factory) -> Generator[AppHarness, None, None]:
  21. with AppHarness.create(
  22. root=tmp_path_factory.mktemp("link_app"),
  23. app_source=LinkApp, # type: ignore
  24. ) as harness:
  25. assert harness.app_instance is not None, "app is not running"
  26. yield harness
  27. def test_link_hover(link_app: AppHarness, page: Page):
  28. assert link_app.frontend_url is not None
  29. page.goto(link_app.frontend_url)
  30. link = page.get_by_role("link")
  31. expect(link).to_have_text("Click me")
  32. expect(link).to_have_css("color", "rgb(0, 0, 255)")
  33. link.hover()
  34. expect(link).to_have_css("color", "rgb(255, 0, 0)")