Skip to content

Commit dde4eee

Browse files
committed
Refactor and fix lint
1 parent 3259454 commit dde4eee

File tree

5 files changed

+34
-45
lines changed

5 files changed

+34
-45
lines changed

src/js/packages/@reactpy/client/src/vdom.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import eventToObject from "event-to-object";
2+
import { Fragment } from "preact";
23
import type {
34
ReactPyVdom,
45
ReactPyVdomImportSource,

tests/test_reactjs/test_modules.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from pathlib import Path
2+
13
import pytest
24

35
import reactpy
46
from reactpy import html
57
from reactpy.reactjs import component_from_string, import_reactjs
68
from reactpy.testing import BackendFixture, DisplayFixture
79

10+
JS_FIXTURES_DIR = Path(__file__).parent / "js_fixtures"
11+
812

913
@pytest.fixture(scope="module")
1014
async def display(browser):
@@ -89,3 +93,24 @@ def App():
8993
elements = await display.page.query_selector_all(".component-c")
9094
assert len(elements) == 2
9195
await display.page.wait_for_selector("#deep-server")
96+
97+
98+
async def test_nest_custom_component_under_web_component(display: DisplayFixture):
99+
"""
100+
Fix https://github.com/reactive-python/reactpy/discussions/1323
101+
102+
Custom components (i.e those wrapped in the component decorator) were not able to
103+
be nested under web components.
104+
"""
105+
Container = reactpy.reactjs.component_from_file(
106+
JS_FIXTURES_DIR / "nest-custom-under-web.js", "Container", name="nest-custom-under-web"
107+
)
108+
109+
@reactpy.component
110+
def CustomComponent():
111+
return reactpy.html.div(reactpy.html.h1({"id": "my-header"}, "Header 1"))
112+
113+
await display.show(lambda: Container(CustomComponent()))
114+
115+
element = await display.page.wait_for_selector("#my-header", state="attached")
116+
assert await element.inner_text() == "Header 1"

tests/test_web/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
THESE ARE TESTS FOR THE LEGACY API. SEE tests/test_reactjs/* FOR THE NEW API TESTS.
3+
THE CONTENTS OF THIS MODULE WILL BE MIGRATED OR DELETED ONCE THE LEGACY API IS REMOVED.
4+
"""

tests/test_web/js_fixtures/nest-custom-under-web.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/test_web/test_module.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# THESE ARE TESTS FOR THE LEGACY API. SEE tests/test_reactjs/* FOR THE NEW API TESTS.
2-
# THIS MODULE WILL BE MIGRATED OR DELETED ONCE THE LEGACY API IS REMOVED.
1+
"""
2+
THESE ARE TESTS FOR THE LEGACY API. SEE tests/test_reactjs/* FOR THE NEW API TESTS.
3+
THE CONTENTS OF THIS MODULE WILL BE MIGRATED OR DELETED ONCE THE LEGACY API IS REMOVED.
4+
"""
35
from pathlib import Path
46

57
import pytest
@@ -563,32 +565,3 @@ async def test_module_without_bind(display: DisplayFixture):
563565
"#my-generic-component", state="attached"
564566
)
565567
assert await element.inner_text() == "Hello World"
566-
567-
async def test_nest_custom_component_under_web_component(display: DisplayFixture):
568-
"""
569-
Fix https://github.com/reactive-python/reactpy/discussions/1323
570-
571-
Custom components (i.e those wrapped in the component decorator) were not able to
572-
be nested under web components.
573-
574-
"""
575-
module = reactpy.reactjs.file_to_module(
576-
"nest-custom-under-web", JS_FIXTURES_DIR / "nest-custom-under-web.js"
577-
)
578-
Container = reactpy.reactjs.module_to_vdom(module, "Container")
579-
580-
@reactpy.component
581-
def CustomComponent():
582-
return reactpy.html.div(
583-
reactpy.html.h1({"id": "my-header"}, "Header 1")
584-
)
585-
await display.show(
586-
lambda: Container(
587-
CustomComponent()
588-
)
589-
)
590-
591-
element = await display.page.wait_for_selector(
592-
"#my-header", state="attached"
593-
)
594-
assert await element.inner_text() == "Header 1"

0 commit comments

Comments
 (0)