-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Archmonger <[email protected]>
- Loading branch information
1 parent
23c0a77
commit 785d3d2
Showing
4 changed files
with
81 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
from reactpy import component, html | ||
from reactpy.testing import DisplayFixture | ||
|
||
from reactpy_router import browser_router, route | ||
|
||
from .utils import page_load_complete | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_router_simple(display: DisplayFixture): | ||
"""Confirm the number of rendering operations when new pages are first loaded""" | ||
root_render_count = 0 | ||
home_page_render_count = 0 | ||
not_found_render_count = 0 | ||
|
||
@component | ||
def root(): | ||
nonlocal root_render_count | ||
root_render_count += 1 | ||
|
||
@component | ||
def home_page(): | ||
nonlocal home_page_render_count | ||
home_page_render_count += 1 | ||
return html.h1("Home Page 🏠") | ||
|
||
@component | ||
def not_found(): | ||
nonlocal not_found_render_count | ||
not_found_render_count += 1 | ||
return html.h1("Missing Link 🔗💥") | ||
|
||
return browser_router( | ||
route("/", home_page()), | ||
route("{404:any}", not_found()), | ||
) | ||
|
||
await display.show(root) | ||
await page_load_complete(display.page) | ||
|
||
assert root_render_count == 1 | ||
assert home_page_render_count == 1 | ||
assert not_found_render_count == 0 | ||
|
||
await display.goto("/xxx") | ||
await page_load_complete(display.page) | ||
|
||
assert root_render_count == 2 | ||
assert home_page_render_count == 1 | ||
assert not_found_render_count == 1 | ||
|
||
await display.goto("/yyy") | ||
await page_load_complete(display.page) | ||
|
||
assert root_render_count == 3 | ||
assert home_page_render_count == 1 | ||
assert not_found_render_count == 2 | ||
|
||
assert True |
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,7 @@ | ||
from playwright.async_api._generated import Page | ||
|
||
|
||
async def page_load_complete(page: Page) -> None: | ||
"""Only return when network is idle and DOM has loaded""" | ||
await page.wait_for_load_state("networkidle") | ||
await page.wait_for_load_state("domcontentloaded") |