Skip to content

Commit 2728d83

Browse files
committed
added test
1 parent 6771920 commit 2728d83

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/integration/callbacks/test_callback_context.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import operator
33
import pytest
44

5-
from dash import Dash, Input, Output, html, dcc, callback_context, ctx
5+
from dash import Dash, ALL, Input, Output, html, dcc, callback_context, ctx
66

77
from dash.exceptions import PreventUpdate, MissingCallbackContextException
88
import dash.testing.wait as wait
@@ -355,3 +355,29 @@ def on_click(*args):
355355
for btn in btns:
356356
dash_duo.find_element("#" + btn).click()
357357
dash_duo.wait_for_text_to_equal("#output", f"Just clicked {btn}")
358+
359+
360+
def test_cbcx008_triggered_id_pmc(dash_duo):
361+
362+
app = Dash()
363+
app.layout = html.Div(
364+
[
365+
html.Button("Click me", id={"type": "btn", "index": "myindex"}),
366+
html.Div(id="output"),
367+
]
368+
)
369+
370+
@app.callback(
371+
Output("output", "children"), Input({"type": "btn", "index": ALL}, "n_clicks")
372+
)
373+
def func(n_clicks):
374+
if ctx.triggered:
375+
triggered_id, dict_id = next(iter(ctx.triggered_ids.items()))
376+
if dict_id == {"type": "btn", "index": "myindex"}:
377+
return dict_id["index"]
378+
379+
dash_duo.start_server(app)
380+
dash_duo.find_element(
381+
'#\\{\\"index\\"\\:\\"myindex\\"\\,\\"type\\"\\:\\"btn\\"\\}'
382+
).click()
383+
dash_duo.wait_for_text_to_equal("#output", "myindex")

0 commit comments

Comments
 (0)