-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a config variable to add extra overlay components (#4763)
* add a config variable to add extra overlay components * add integration test * Apply suggestions from code review --------- Co-authored-by: Masen Furer <[email protected]>
- Loading branch information
1 parent
88eae92
commit 6f4d328
Showing
4 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Test case for adding an overlay component defined in the rxconfig.""" | ||
|
||
from typing import Generator | ||
|
||
import pytest | ||
from selenium.webdriver.common.by import By | ||
|
||
from reflex.testing import AppHarness, WebDriver | ||
|
||
|
||
def ExtraOverlay(): | ||
import reflex as rx | ||
|
||
rx.config.get_config().extra_overlay_function = "reflex.components.moment.moment" | ||
|
||
def index(): | ||
return rx.vstack( | ||
rx.el.input( | ||
id="token", | ||
value=rx.State.router.session.client_token, | ||
is_read_only=True, | ||
), | ||
rx.text( | ||
"Hello World", | ||
), | ||
) | ||
|
||
app = rx.App(_state=rx.State) | ||
app.add_page(index) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def extra_overlay(tmp_path_factory) -> Generator[AppHarness, None, None]: | ||
"""Start ExtraOverlay app at tmp_path via AppHarness. | ||
Args: | ||
tmp_path_factory: pytest tmp_path_factory fixture | ||
Yields: | ||
running AppHarness instance | ||
""" | ||
with AppHarness.create( | ||
root=tmp_path_factory.mktemp("extra_overlay"), | ||
app_source=ExtraOverlay, | ||
) as harness: | ||
assert harness.app_instance is not None, "app is not running" | ||
yield harness | ||
|
||
|
||
@pytest.fixture | ||
def driver(extra_overlay: AppHarness): | ||
"""Get an instance of the browser open to the extra overlay app. | ||
Args: | ||
extra_overlay: harness for the ExtraOverlay app. | ||
Yields: | ||
WebDriver instance. | ||
""" | ||
driver = extra_overlay.frontend() | ||
try: | ||
token_input = driver.find_element(By.ID, "token") | ||
assert token_input | ||
# wait for the backend connection to send the token | ||
token = extra_overlay.poll_for_value(token_input) | ||
assert token is not None | ||
|
||
yield driver | ||
finally: | ||
driver.quit() | ||
|
||
|
||
def test_extra_overlay(driver: WebDriver, extra_overlay: AppHarness): | ||
"""Test the ExtraOverlay app. | ||
Args: | ||
driver: WebDriver instance. | ||
extra_overlay: harness for the ExtraOverlay app. | ||
""" | ||
# Check that the text is displayed. | ||
text = driver.find_element(By.XPATH, "//*[contains(text(), 'Hello World')]") | ||
assert text | ||
assert text.text == "Hello World" | ||
|
||
time = driver.find_element(By.TAG_NAME, "time") | ||
assert time | ||
assert time.text |