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 @@