Skip to content

Commit e1ff1ce

Browse files
committed
Test written
1 parent b1e01cc commit e1ff1ce

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "https://esm.sh/[email protected]"
2+
import ReactDOM from "https://esm.sh/[email protected]/client"
3+
import GridLayout from "https://esm.sh/[email protected]";
4+
export {GridLayout};
5+
6+
export function bind(node, config) {
7+
debugger;
8+
const root = ReactDOM.createRoot(node);
9+
return {
10+
create: (type, props, children) =>
11+
React.createElement(type, props, children),
12+
render: (element) => root.render(element, node),
13+
unmount: () => root.unmount()
14+
};
15+
}

tests/test_web/test_module.py

+54
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,60 @@ async def test_imported_components_can_render_children(display: DisplayFixture):
208208
assert (await child.get_attribute("id")) == f"child-{index + 1}"
209209

210210

211+
async def test_keys_properly_propagated(display: DisplayFixture):
212+
module = reactpy.web.module_from_file(
213+
"keys-properly-propagated", JS_FIXTURES_DIR / "keys-properly-propagated.js"
214+
)
215+
GridLayout = reactpy.web.export(module, "GridLayout")
216+
217+
await display.show(
218+
lambda: GridLayout({
219+
"layout": [
220+
{
221+
"i": "a",
222+
"x": 0,
223+
"y": 0,
224+
"w": 1,
225+
"h": 2,
226+
"static": True,
227+
},
228+
{
229+
"i": "b",
230+
"x": 1,
231+
"y": 0,
232+
"w": 3,
233+
"h": 2,
234+
"minW": 2,
235+
"maxW": 4,
236+
},
237+
{
238+
"i": "c",
239+
"x": 4,
240+
"y": 0,
241+
"w": 1,
242+
"h": 2,
243+
}
244+
],
245+
"cols": 12,
246+
"rowHeight": 30,
247+
"width": 1200,
248+
},
249+
reactpy.html.div({"key": "a"}, "a"),
250+
reactpy.html.div({"key": "b"}, "b"),
251+
reactpy.html.div({"key": "c"}, "c"),
252+
)
253+
)
254+
255+
parent = await display.page.wait_for_selector(".react-grid-layout", state="attached", timeout=0)
256+
children = await parent.query_selector_all("div")
257+
258+
# The children simply will not render unless they receive the key prop
259+
assert len(children) == 3
260+
261+
# for index, child in enumerate(children):
262+
# assert (await child.get_attribute("key")) == child.get_text()
263+
264+
211265
def test_module_from_string():
212266
reactpy.web.module_from_string("temp", "old")
213267
with assert_reactpy_did_log(r"Existing web module .* will be replaced with"):

0 commit comments

Comments
 (0)