reflex/integration/test_tailwind.py
Masen Furer 26002a809b
[REF-3591] Remove chakra-related files from immutable vars PR (#3821)
* Add comments to html metadata component (#3731)

* fix: add verification for path /404 (#3723)

Co-authored-by: coolstorm <manas.gupta@fampay.in>

* Use the new state name when setting `is_hydrated` to false (#3738)

* Use `._is_mutable()` to account for parent state proxy (#3739)

When a parent state proxy is set, also allow child StateProxy._self_mutable to
override the parent's `_is_mutable()`.

* bump to 0.5.9 (#3746)

* add message when installing requirements.txt is needed for chosen template during init (#3750)

* #3752 bugfix add domain for XAxis (#3764)

* fix appharness app_source typing (#3777)

* fix import clash between connectionToaster and hooks.useState (#3749)

* use different registry when in china, fixes #3700 (#3702)

* do not reload compilation if using local app in AppHarness (#3790)

* do not reload if using local app

* Update reflex/testing.py

Co-authored-by: Masen Furer <m_github@0x26.net>

---------

Co-authored-by: Masen Furer <m_github@0x26.net>

* Bump memory on relevant actions (#3781)

Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>

* [REF-3334] Validate Toast Props (#3793)

* [REF-3536][REF-3537][REF-3541] Move chakra components into its repo(reflex-chakra) (#3798)

* fix get_uuid_string_var (#3795)

* minor State cleanup (#3768)

* Fix code wrap in markdown (#3755)

---------

Co-authored-by: Alek Petuskey <alek@pynecone.io>
Co-authored-by: Manas Gupta <53006261+Manas1820@users.noreply.github.com>
Co-authored-by: coolstorm <manas.gupta@fampay.in>
Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>
Co-authored-by: Shubhankar Dimri <dimrishubhi@gmail.com>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
2024-08-22 16:15:12 -07:00

125 lines
4.1 KiB
Python

"""Test case for disabling tailwind in the config."""
import functools
from typing import Generator
import pytest
from selenium.webdriver.common.by import By
from reflex.testing import AppHarness
PARAGRAPH_TEXT = "Tailwind Is Cool"
PARAGRAPH_CLASS_NAME = "text-red-500"
TEXT_RED_500_COLOR = ["rgba(239, 68, 68, 1)", "rgb(239, 68, 68)"]
def TailwindApp(
tailwind_disabled: bool = False,
paragraph_text: str = PARAGRAPH_TEXT,
paragraph_class_name: str = PARAGRAPH_CLASS_NAME,
):
"""App with tailwind optionally disabled.
Args:
tailwind_disabled: Whether tailwind is disabled for the app.
paragraph_text: Text for the paragraph.
paragraph_class_name: Tailwind class_name for the paragraph.
"""
from pathlib import Path
import reflex_chakra as rc
import reflex as rx
class UnusedState(rx.State):
pass
def index():
return rx.el.div(
rc.text(paragraph_text, class_name=paragraph_class_name),
rx.el.p(paragraph_text, class_name=paragraph_class_name),
rx.text(paragraph_text, as_="p", class_name=paragraph_class_name),
rx.el.div("Test external stylesheet", class_name="external"),
id="p-content",
)
assets = Path(__file__).resolve().parent.parent / "assets"
assets.mkdir(exist_ok=True)
stylesheet = assets / "test_styles.css"
stylesheet.write_text(".external { color: rgba(0, 0, 255, 0.5) }")
app = rx.App(style={"font_family": "monospace"}, stylesheets=[stylesheet.name])
app.add_page(index)
if tailwind_disabled:
config = rx.config.get_config()
config.tailwind = None
@pytest.fixture(params=[False, True], ids=["tailwind_enabled", "tailwind_disabled"])
def tailwind_disabled(request) -> bool:
"""Tailwind disabled fixture.
Args:
request: pytest request fixture.
Returns:
True if tailwind is disabled, False otherwise.
"""
return request.param
@pytest.fixture()
def tailwind_app(tmp_path, tailwind_disabled) -> Generator[AppHarness, None, None]:
"""Start TailwindApp app at tmp_path via AppHarness with tailwind disabled via config.
Args:
tmp_path: pytest tmp_path fixture
tailwind_disabled: Whether tailwind is disabled for the app.
Yields:
running AppHarness instance
"""
with AppHarness.create(
root=tmp_path,
app_source=functools.partial(TailwindApp, tailwind_disabled=tailwind_disabled), # type: ignore
app_name="tailwind_disabled_app" if tailwind_disabled else "tailwind_app",
) as harness:
yield harness
def test_tailwind_app(tailwind_app: AppHarness, tailwind_disabled: bool):
"""Test that the app can compile without tailwind.
Args:
tailwind_app: AppHarness instance.
tailwind_disabled: Whether tailwind is disabled for the app.
"""
assert tailwind_app.app_instance is not None
assert tailwind_app.backend is not None
driver = tailwind_app.frontend()
# Assert the app is stateless.
with pytest.raises(ValueError) as errctx:
_ = tailwind_app.app_instance.state_manager
errctx.match("The state manager has not been initialized.")
# Assert content is visible (and not some error)
content = driver.find_element(By.ID, "p-content")
paragraphs = content.find_elements(By.TAG_NAME, "p")
assert len(paragraphs) == 3
for p in paragraphs:
assert tailwind_app.poll_for_content(p, exp_not_equal="") == PARAGRAPH_TEXT
assert p.value_of_css_property("font-family") == '"monospace"'
if tailwind_disabled:
# expect default color, not "text-red-500" from tailwind utility class
assert p.value_of_css_property("color") not in TEXT_RED_500_COLOR
else:
# expect "text-red-500" from tailwind utility class
assert p.value_of_css_property("color") in TEXT_RED_500_COLOR
# Assert external stylesheet is applying rules
external = driver.find_elements(By.CLASS_NAME, "external")
assert len(external) == 1
for ext_div in external:
assert ext_div.value_of_css_property("color") == "rgba(0, 0, 255, 0.5)"