Skip to content

Commit 8d024b4

Browse files
committed
🐅 tests both vanilla and pattern-matching callbacks
1 parent b9ab937 commit 8d024b4

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

tests/integration/clientside/test_clientside.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -368,57 +368,56 @@ def update_output(value):
368368
dash_duo.wait_for_text_to_equal("#output-clientside", 'Client says "hello world"')
369369

370370

371-
def test_clsd009_clientside_callback_context(dash_duo):
371+
def test_clsd009_clientside_callback_context_triggered(dash_duo):
372372
app = Dash(__name__, assets_folder="assets")
373373

374374
app.layout = html.Div(
375375
[
376-
html.Button("0", id={"btn": 0}),
377-
html.Button("1", id={"btn": 1}),
378-
html.Button("2", id={"btn": 2}),
376+
html.Button("btn0", id="btn0"),
377+
html.Button("btn1:0", id={"btn1": 0}),
378+
html.Button("btn1:1", id={"btn1": 1}),
379+
html.Button("btn1:2", id={"btn1": 2}),
379380
html.Div(id="output-clientside"),
380-
html.Div(id="output-serverside"),
381381
]
382382
)
383383

384-
@app.callback(
385-
Output("output-serverside", "children"), [Input({"btn": ALL}, "n_clicks")]
386-
)
387-
def update_output(n_clicks):
388-
return "triggered: %s" % dash.callback_context.triggered
389-
390384
app.clientside_callback(
391385
"""
392-
function (n_clicks) {
386+
function (n_clicks0, n_clicks1) {
393387
console.log(dash_clientside.callback_context)
394388
return `triggered: ${JSON.stringify(dash_clientside.callback_context.triggered)}`
395389
}
396390
""",
397391
Output("output-clientside", "children"),
398-
[Input({"btn": ALL}, "n_clicks")],
392+
[Input("btn0", "n_clicks"),
393+
Input({"btn1": ALL}, "n_clicks")],
399394
)
400395

401396
dash_duo.start_server(app)
402397

403398
dash_duo.wait_for_text_to_equal(
404-
"#output-serverside", "triggered: [{'prop_id': '.', 'value': None}]"
399+
"#output-clientside", r'triggered: [{"prop_id":".","value":null}]'
405400
)
401+
402+
dash_duo.find_element("#btn0").click()
403+
406404
dash_duo.wait_for_text_to_equal(
407-
"#output-clientside", r'triggered: [{"prop_id":".","value":null}]'
405+
"#output-clientside",
406+
r'triggered: [{"prop_id":"btn0.n_clicks","value":1}]',
408407
)
409408

410-
dash_duo.find_element("button[id*='0']").click()
409+
dash_duo.find_element("button[id*='btn1\":0']").click()
411410

412411
dash_duo.wait_for_text_to_equal(
413412
"#output-clientside",
414-
r'triggered: [{"prop_id":"{\"btn\":0}.n_clicks","value":1}]',
413+
r'triggered: [{"prop_id":"{\"btn1\":0}.n_clicks","value":1}]',
415414
)
416415

417-
dash_duo.find_element("button[id*='2']").click()
416+
dash_duo.find_element("button[id*='btn1\":2']").click()
418417

419418
dash_duo.wait_for_text_to_equal(
420419
"#output-clientside",
421-
r'triggered: [{"prop_id":"{\"btn\":2}.n_clicks","value":1}]',
420+
r'triggered: [{"prop_id":"{\"btn1\":2}.n_clicks","value":1}]',
422421
)
423422

424423
# TODO: flush out these tests and make them look prettier.

0 commit comments

Comments
 (0)