-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add integration tests for frontend path #5712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tartansandal
wants to merge
15
commits into
reflex-dev:main
Choose a base branch
from
tartansandal:kjh/integration-tests-for-frontend-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−6
Open
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2198a74
Add integration tests for frontend_path configuration
tartansandal 2abec69
Set an xfail mark noting the bug
tartansandal 812b168
Update reflex/environment.py
tartansandal 243726e
Update tests/integration/tests_playwright/test_frontend_path.py
tartansandal 2a06383
Adjust environment variable commment to match config comment
tartansandal 64cf139
Remove duplication introduced by online suggestion
tartansandal cc23e8b
Ensure link test fixture does not display a buiit with reflex badge
tartansandal b5d9053
Merge branch 'main' into kjh/integration-tests-for-frontend-path
tartansandal 4c07953
Remove the xfail after merge from main
tartansandal 989f86e
Add docstrings for functions and classes
tartansandal badab5b
Add a test to ensure 404's still work as expected
tartansandal ca32c73
Switch to using get_by_role for buttons
tartansandal 02650f3
Check url at each step
tartansandal bbe8847
Switch to using isolated tmp dirs for test fixtures
tartansandal 9aebd43
Extend tests to cover onmount case
tartansandal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
105 changes: 105 additions & 0 deletions
105
tests/integration/tests_playwright/test_frontend_path.py
This file contains hidden or 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,105 @@ | ||
| from collections.abc import Generator | ||
|
|
||
| import pytest | ||
| from playwright.sync_api import Page, expect | ||
|
|
||
| from reflex.environment import environment | ||
| from reflex.testing import AppHarness, AppHarnessProd | ||
|
|
||
|
|
||
| def OnLoadRedirectApp(): | ||
| import reflex as rx | ||
|
|
||
| @rx.page("/") | ||
| def index(): | ||
| return rx.container( | ||
| rx.input( | ||
| value=rx.State.router.session.client_token, | ||
| read_only=True, | ||
| id="token", | ||
| ), | ||
| rx.vstack( | ||
| rx.heading("This is the index page!"), | ||
| rx.button("Go to Subpage!", on_click=rx.redirect("/subpage")), | ||
| ), | ||
| ) | ||
|
|
||
| @rx.page("/subpage") | ||
| def subpage(): | ||
| return rx.container( | ||
| rx.vstack( | ||
| rx.heading("This is the sub page!"), | ||
| rx.button("Go to index!", on_click=rx.redirect("/")), | ||
| rx.button("Bounce to index!", on_click=rx.redirect("/bouncer")), | ||
| ) | ||
| ) | ||
|
|
||
| @rx.page("/bouncer", on_load=rx.redirect("/")) | ||
| def bouncer(): | ||
| return rx.container( | ||
| rx.vstack( | ||
| rx.heading("This is the bouncer page!"), | ||
| rx.text("You should not be here!"), | ||
| rx.button("Go to index!", on_click=rx.redirect("/")), | ||
| ), | ||
| ) | ||
|
|
||
| app = rx.App() # noqa: F841 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def onload_redirect_app(tmp_path_factory) -> Generator[AppHarness, None, None]: | ||
| with AppHarnessProd.create( | ||
| root=tmp_path_factory.mktemp("frontend_path_app"), | ||
| app_source=OnLoadRedirectApp, | ||
| ) as harness: | ||
| assert harness.app_instance is not None, "app is not running" | ||
| yield harness | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def onload_redirect_with_prefix_app( | ||
| tmp_path_factory, | ||
| ) -> Generator[AppHarness, None, None]: | ||
| prefix = "/prefix" | ||
| environment.REFLEX_FRONTEND_PATH.set(prefix) | ||
tartansandal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with AppHarness.create( | ||
| root=tmp_path_factory.mktemp("frontend_path_app"), | ||
| app_source=OnLoadRedirectApp, | ||
| ) as harness: | ||
| assert harness.app_instance is not None, "app is not running" | ||
| yield harness | ||
| environment.REFLEX_FRONTEND_PATH.set("") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("app_fixture_name", "prefix"), | ||
| [ | ||
| ("onload_redirect_app", ""), | ||
| pytest.param( | ||
| "onload_redirect_with_prefix_app", | ||
| "/prefix", | ||
| marks=pytest.mark.xfail(reason="bug #5674"), | ||
| ), | ||
| ], | ||
| ) | ||
| def test_onload_redirect(app_fixture_name: str, prefix: str, page: Page, request): | ||
| app_fixture = request.getfixturevalue(app_fixture_name) | ||
| assert app_fixture.frontend_url is not None | ||
|
|
||
| base_url = app_fixture.frontend_url.rstrip("/") | ||
| base_url += prefix | ||
| page.goto(f"{base_url}/") | ||
| expect(page.get_by_text("This is the index page!")).to_be_visible() | ||
|
|
||
| # Go to /subpage | ||
| page.get_by_text("Go to Subpage!").click() | ||
| expect(page.get_by_text("This is the sub page!")).to_be_visible() | ||
|
|
||
| # Click "Bounce to index!" (should redirect to index via on_load) | ||
| page.get_by_text("Bounce to index!").click() | ||
| expect(page.get_by_text("This is the index page!")).to_be_visible() | ||
|
|
||
| # Optionally, reload /prefix/bouncer/ and check redirect | ||
| page.goto(f"{base_url}/bouncer/") | ||
| expect(page.get_by_text("This is the index page!")).to_be_visible() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.