Skip to content

Commit 3a159af

Browse files
committed
Replaces test for callable non-event prop
1 parent a109a3b commit 3a159af

File tree

3 files changed

+38
-116
lines changed

3 files changed

+38
-116
lines changed

tests/test_web/js_fixtures/ag-grid-react.js

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { h, render } from "https://unpkg.com/preact?module";
2+
import htm from "https://unpkg.com/htm?module";
3+
4+
const html = htm.bind(h);
5+
6+
export function bind(node, config) {
7+
return {
8+
create: (type, props, children) => h(type, props, ...children),
9+
render: (element) => render(element, node),
10+
unmount: () => render(null, node),
11+
};
12+
}
13+
14+
// The intention here is that Child components are passed in here so we check that the
15+
// children of "the-parent" are "child-1" through "child-N"
16+
export function Component(props) {
17+
var text = "DEFAULT";
18+
if (props.setText && typeof props.setText === "function") {
19+
text = props.setText("PREFIX TEXT: ");
20+
}
21+
return html`
22+
<div id="${props.id}">
23+
${text}
24+
</div>
25+
`;
26+
}

tests/test_web/test_module.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
assert_reactpy_did_not_log,
1313
poll,
1414
)
15-
from reactpy.web.module import NAME_SOURCE, WebModule
1615
from reactpy.types import JavaScript
16+
from reactpy.web.module import NAME_SOURCE, WebModule
1717

1818
JS_FIXTURES_DIR = Path(__file__).parent / "js_fixtures"
1919

@@ -390,53 +390,25 @@ async def test_subcomponent_notation_as_obj_attrs(display: DisplayFixture):
390390
assert len(form_label) == 1
391391

392392

393-
async def test_ag_grid_table(display: DisplayFixture):
393+
async def test_callable_prop_with_javacript(display: DisplayFixture):
394394
module = reactpy.web.module_from_file(
395-
"ag-grid-react", JS_FIXTURES_DIR / "ag-grid-react.js"
395+
"callable-prop", JS_FIXTURES_DIR / "callable-prop.js"
396396
)
397-
AgGridReact = reactpy.web.export(module, "AgGridReact")
397+
Component = reactpy.web.export(module, "Component")
398398

399399
@reactpy.component
400400
def App():
401-
dummy_bool, set_dummy_bool = reactpy.hooks.use_state(False)
402-
row_data, set_row_data = reactpy.hooks.use_state([
403-
{ "make": "Tesla", "model": "Model Y", "price": 64950, "electric": True },
404-
{ "make": "Ford", "model": "F-Series", "price": 33850, "electric": False },
405-
{ "make": "Toyota", "model": "Corolla", "price": 29600, "electric": False },
406-
])
407-
col_defs, set_col_defs = reactpy.hooks.use_state([
408-
{ "field": "make" },
409-
{ "field": "model" },
410-
{ "field": "price" },
411-
{ "field": "electric" },
412-
])
413-
default_col_def = {"flex": 1}
414-
row_selection = reactpy.hooks.use_memo(lambda: {"mode": "singleRow"})
415-
416-
return reactpy.html.div(
417-
{"id": "the-parent", "style": {"height": "100vh", "width": "100vw"}, "class": "ag-theme-quartz"},
418-
AgGridReact({
419-
"style": {"height": "500px"},
420-
"rowData": row_data,
421-
"columnDefs": col_defs,
422-
"defaultColDef": default_col_def,
423-
"selection": row_selection,
424-
"onRowSelected": lambda x: set_dummy_bool(not dummy_bool),
425-
"getRowId": JavaScript("(params) => String(params.data.model);")
426-
})
401+
return Component(
402+
{
403+
"id": "my-div",
404+
"setText": JavaScript('(prefixText) => prefixText + "TEST 123"'),
405+
}
427406
)
428407

429-
await display.show(
430-
lambda: App()
431-
)
408+
await display.show(lambda: App())
432409

433-
table_body = await display.page.wait_for_selector(".ag-body-viewport", state="attached")
434-
checkboxes = await table_body.query_selector_all(".ag-checkbox-input")
435-
await checkboxes[0].click()
436-
# Regrab checkboxes, since they should rerender
437-
checkboxes = await table_body.query_selector_all(".ag-checkbox-input")
438-
checked = await checkboxes[0].is_checked()
439-
assert checked is True
410+
my_div = await display.page.wait_for_selector("#my-div", state="attached")
411+
assert await my_div.inner_text() == "PREFIX TEXT: TEST 123"
440412

441413

442414
def test_module_from_string():

0 commit comments

Comments
 (0)