|
1 | 1 | from multiprocessing import Lock |
2 | | -from dash import Dash, Input, Output, dcc, html |
| 2 | +from dash import Dash, Input, Output, dcc, html, MATCH, ALL |
3 | 3 | from dash.dependencies import stringify_id |
4 | 4 | from dash.testing import wait |
5 | 5 | import time |
@@ -417,7 +417,7 @@ def updateDiv(n_clicks): |
417 | 417 |
|
418 | 418 | # update multiple props of same component, only targeted id/prop triggers spinner |
419 | 419 | # test that target_components id can be a dict id |
420 | | -def test_ldcp011_loading_component_target_components(dash_dcc): |
| 420 | +def test_ldcp010_loading_component_target_components(dash_dcc): |
421 | 421 | lock = Lock() |
422 | 422 |
|
423 | 423 | app = Dash(__name__) |
@@ -461,7 +461,7 @@ def updateDiv2(n_clicks): |
461 | 461 |
|
462 | 462 | dash_dcc.start_server(app) |
463 | 463 |
|
464 | | - btn1id = "#" + stringify_id({"type": "button", "index": "one"}) |
| 464 | + btn1id = "[id='" + stringify_id({"type": "button", "index": "one"}) + "']" |
465 | 465 |
|
466 | 466 | dash_dcc.wait_for_text_to_equal(btn1id, "content 1") |
467 | 467 |
|
@@ -839,3 +839,50 @@ def update_btn1_children(n_clicks): |
839 | 839 | assert spinners == [] |
840 | 840 |
|
841 | 841 | assert dash_dcc.get_logs() == [] |
| 842 | + |
| 843 | + |
| 844 | +# loading spinner triggers when callback Output uses ALL wildcard |
| 845 | +def test_ldcp019_loading_component_pattern_matching(dash_dcc): |
| 846 | + lock = Lock() |
| 847 | + |
| 848 | + app = Dash(__name__) |
| 849 | + |
| 850 | + app.layout = html.Div( |
| 851 | + [ |
| 852 | + dcc.Loading( |
| 853 | + [ |
| 854 | + html.Div( |
| 855 | + id={"type": "div-1", "index": 1, "name": "test"}, |
| 856 | + className="div-1", |
| 857 | + ) |
| 858 | + ], |
| 859 | + className="loading", |
| 860 | + ) |
| 861 | + ], |
| 862 | + id={"type": "root", "index": 1, "name": "test"}, |
| 863 | + className="root", |
| 864 | + ) |
| 865 | + |
| 866 | + @app.callback( |
| 867 | + Output({"type": "div-1", "index": ALL, "name": MATCH}, "children"), |
| 868 | + Input({"type": "root", "index": ALL, "name": MATCH}, "n_clicks"), |
| 869 | + ) |
| 870 | + def updateDiv(n_clicks): |
| 871 | + if n_clicks == [1]: |
| 872 | + time.sleep(0.1) |
| 873 | + return ["changed"] |
| 874 | + return ["content"] |
| 875 | + |
| 876 | + with lock: |
| 877 | + dash_dcc.start_server(app) |
| 878 | + dash_dcc.wait_for_text_to_equal(".div-1", "content") |
| 879 | + |
| 880 | + dash_dcc.find_element(".root").click() |
| 881 | + |
| 882 | + dash_dcc.find_element(".loading .dash-spinner") |
| 883 | + # mounted but hidden, so looks like no text |
| 884 | + dash_dcc.wait_for_text_to_equal(".div-1", "") |
| 885 | + |
| 886 | + dash_dcc.wait_for_text_to_equal(".div-1", "changed") |
| 887 | + |
| 888 | + assert dash_dcc.get_logs() == [] |
0 commit comments