1
1
from multiprocessing import Lock
2
2
from dash import Dash , Input , Output , dcc , html
3
+ from dash .dependencies import stringify_id
3
4
from dash .testing import wait
4
5
import time
5
6
@@ -414,9 +415,9 @@ def updateDiv(n_clicks):
414
415
assert dash_dcc .get_logs () == []
415
416
416
417
417
- # multiple components , only one triggers the spinner
418
- def test_ldcp010_loading_component_target_components ( dash_dcc ):
419
-
418
+ # update multiple props of same component , only targeted id/prop triggers spinner
419
+ # test that target_components id can be a dict id
420
+ def test_ldcp011_loading_component_target_components ( dash_dcc ):
420
421
lock = Lock ()
421
422
422
423
app = Dash (__name__ )
@@ -425,53 +426,61 @@ def test_ldcp010_loading_component_target_components(dash_dcc):
425
426
[
426
427
dcc .Loading (
427
428
[
428
- html .Button (id = "btn-1" ),
429
+ html .Button (id = { "type" : "button" , "index" : "one" } ),
429
430
html .Button (id = "btn-2" ),
431
+ html .Button (id = "btn-3" ),
430
432
],
431
433
className = "loading-1" ,
432
- target_components = {"btn-2" : "children" },
434
+ target_components = {
435
+ stringify_id ({"type" : "button" , "index" : "one" }): "className"
436
+ },
433
437
)
434
438
],
435
439
id = "root" ,
436
440
)
437
441
438
- @app .callback (Output ("btn-1" , "children" ), [Input ("btn-2" , "n_clicks" )])
442
+ @app .callback (
443
+ Output ({"type" : "button" , "index" : "one" }, "children" ),
444
+ [Input ("btn-2" , "n_clicks" )],
445
+ )
439
446
def updateDiv1 (n_clicks ):
440
447
if n_clicks :
441
448
with lock :
442
449
return "changed 1"
443
-
444
450
return "content 1"
445
451
446
- @app .callback (Output ("btn-2" , "children" ), [Input ("btn-1" , "n_clicks" )])
452
+ @app .callback (
453
+ Output ({"type" : "button" , "index" : "one" }, "className" ),
454
+ [Input ("btn-3" , "n_clicks" )],
455
+ )
447
456
def updateDiv2 (n_clicks ):
448
457
if n_clicks :
449
458
with lock :
450
- return "changed 2"
451
-
452
- return "content 2"
459
+ return "new-class"
460
+ return ""
453
461
454
462
dash_dcc .start_server (app )
455
463
456
- dash_dcc .wait_for_text_to_equal ("#btn-1" , "content 1" )
457
- dash_dcc .wait_for_text_to_equal ("#btn-2" , "content 2" )
464
+ btn1id = "#" + stringify_id ({"type" : "button" , "index" : "one" })
458
465
459
- with lock :
460
- dash_dcc .find_element ("#btn-1" ).click ()
461
-
462
- dash_dcc .find_element (".loading-1 .dash-spinner" )
463
- dash_dcc .wait_for_text_to_equal ("#btn-2" , "" )
464
-
465
- dash_dcc .wait_for_text_to_equal ("#btn-2" , "changed 2" )
466
+ dash_dcc .wait_for_text_to_equal (btn1id , "content 1" )
466
467
467
468
with lock :
468
469
dash_dcc .find_element ("#btn-2" ).click ()
469
- spinners = dash_dcc .find_elements (".loading-1 .dash-spinner" )
470
- dash_dcc .wait_for_text_to_equal ("#btn-1" , "" )
471
470
472
- dash_dcc .wait_for_text_to_equal ("#btn-1" , "changed 1" )
471
+ spinners = dash_dcc .find_elements (".loading-1 .dash-spinner" )
472
+ dash_dcc .wait_for_text_to_equal (btn1id , "" )
473
+ dash_dcc .wait_for_text_to_equal (btn1id , "changed 1" )
473
474
assert spinners == []
474
475
476
+ with lock :
477
+ dash_dcc .find_element ("#btn-3" ).click ()
478
+
479
+ dash_dcc .find_element (".loading-1 .dash-spinner" )
480
+ dash_dcc .wait_for_text_to_equal (btn1id , "" )
481
+
482
+ dash_dcc .wait_for_class_to_equal (btn1id , "new-class" )
483
+
475
484
assert dash_dcc .get_logs () == []
476
485
477
486
0 commit comments