@@ -558,3 +558,64 @@ def update_container2(n_clicks):
558
558
# persistenceTransforms should return upper case strings
559
559
dash_duo .wait_for_text_to_equal ("#component-propName" , "ALPACA" )
560
560
dash_duo .wait_for_text_to_equal ("#component-propPart" , "ARTICHOKE" )
561
+
562
+
563
+ def test_rdps014_save_callback_persistence (dash_duo ):
564
+ app = dash .Dash (__name__ )
565
+
566
+ def make_input (persistence ):
567
+ return dcc .Input (id = "persisted" , value = "a" , persistence = persistence )
568
+
569
+ app .layout = html .Div (
570
+ [
571
+ dcc .Input (id = "persistence-val" , value = "" ),
572
+ dcc .Input (id = "persistence-key" , value = "" ),
573
+ html .Div (make_input ("" ), id = "persisted-container" ),
574
+ html .Div (id = "out" ),
575
+ ]
576
+ )
577
+
578
+ # this is not a good way to set persistence, as it doesn't allow you to
579
+ # get the right initial value. Much better is to update the whole component
580
+ # as we do in the previous test case... but it shouldn't break this way.
581
+ @app .callback (
582
+ Output ("persisted" , "persistence" ), [Input ("persistence-key" , "value" )]
583
+ )
584
+ def set_persistence (val ):
585
+ return val
586
+
587
+ @app .callback (Output ("persisted" , "value" ), [Input ("persistence-val" , "value" )])
588
+ def set_value (val ):
589
+ return val
590
+
591
+ @app .callback (Output ("out" , "children" ), [Input ("persisted" , "value" )])
592
+ def set_out (val ):
593
+ return val
594
+
595
+ dash_duo .start_server (app )
596
+
597
+ dash_duo .wait_for_text_to_equal ("#out" , "" )
598
+
599
+ dash_duo .find_element ("#persistence-key" ).send_keys ("a" )
600
+ time .sleep (0.2 )
601
+ assert not dash_duo .get_logs ()
602
+ dash_duo .wait_for_text_to_equal ("#out" , "" )
603
+ dash_duo .find_element ("#persistence-val" ).send_keys ("alpaca" )
604
+ dash_duo .wait_for_text_to_equal ("#out" , "alpaca" )
605
+
606
+ dash_duo .find_element ("#persistence-key" ).send_keys ("b" )
607
+ dash_duo .wait_for_text_to_equal ("#out" , "" )
608
+ dash_duo .clear_input ("#persistence-val" )
609
+ dash_duo .find_element ("#persistence-val" ).send_keys ("artichoke" )
610
+ dash_duo .wait_for_text_to_equal ("#out" , "artichoke" )
611
+
612
+ # no persistence, still goes back to original value
613
+ dash_duo .clear_input ("#persistence-key" )
614
+ dash_duo .wait_for_text_to_equal ("#out" , "" )
615
+
616
+ # apricot and artichoke saved
617
+ dash_duo .find_element ("#persistence-key" ).send_keys ("a" )
618
+ dash_duo .wait_for_text_to_equal ("#out" , "alpaca" )
619
+ dash_duo .find_element ("#persistence-key" ).send_keys ("b" )
620
+ assert not dash_duo .get_logs ()
621
+ dash_duo .wait_for_text_to_equal ("#out" , "artichoke" )
0 commit comments