From b0bdbfc1797068febe0da6aa397645152368f52c Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:35:43 -0700 Subject: [PATCH] use_user test --- tests/test_app/prerender/components.py | 16 ++++++++++++++++ tests/test_app/templates/prerender.html | 2 ++ tests/test_app/tests/test_components.py | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/tests/test_app/prerender/components.py b/tests/test_app/prerender/components.py index 0ae4af0e..1dc013f3 100644 --- a/tests/test_app/prerender/components.py +++ b/tests/test_app/prerender/components.py @@ -38,3 +38,19 @@ def inner(value): return inner("prerender_component: Prerendered") return inner("prerender_component: Fully Rendered") + + +@component +def use_user(): + user = reactpy_django.hooks.use_user() + scope = reactpy_django.hooks.use_scope() + success = bool(user) + + if scope.get("type") == "http": + return html.div( + {"id": "use-user-http", "data-success": success}, f"use_user: {user} (HTTP)" + ) + + return html.div( + {"id": "use-user-ws", "data-success": success}, f"use_user: {user} (WebSocket)" + ) diff --git a/tests/test_app/templates/prerender.html b/tests/test_app/templates/prerender.html index 03befec5..ed571554 100644 --- a/tests/test_app/templates/prerender.html +++ b/tests/test_app/templates/prerender.html @@ -25,6 +25,8 @@

ReactPy Prerender Test Page

{% component "test_app.prerender.components.prerender_component" class="prerender-component" prerender="true" %}
+ {% component "test_app.prerender.components.use_user" prerender="true" %} +
diff --git a/tests/test_app/tests/test_components.py b/tests/test_app/tests/test_components.py index a5db4159..236edeab 100644 --- a/tests/test_app/tests/test_components.py +++ b/tests/test_app/tests/test_components.py @@ -368,10 +368,13 @@ def test_prerender(self): string = new_page.locator("#prerender_string") vdom = new_page.locator("#prerender_vdom") component = new_page.locator("#prerender_component") + use_user_http = new_page.locator("#use-user-http[data-success=True]") + use_user_ws = new_page.locator("#use-user-ws[data-success=true]") string.wait_for() vdom.wait_for() component.wait_for() + use_user_http.wait_for() # Check if the prerender occurred self.assertEqual( @@ -390,6 +393,7 @@ def test_prerender(self): self.assertEqual( component.all_inner_texts(), ["prerender_component: Fully Rendered"] ) + use_user_ws.wait_for() finally: new_page.close()