Skip to content

Commit 91a615d

Browse files
Added persistence callback test.
1 parent 82b50dd commit 91a615d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/integration/renderer/test_persistence.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,66 @@ def update_container2(n_clicks):
558558
# persistenceTransforms should return upper case strings
559559
dash_duo.wait_for_text_to_equal("#component-propName", "ALPACA")
560560
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(
588+
Output("persisted", "value"), [Input("persistence-val", "value")]
589+
)
590+
def set_value(val):
591+
return val
592+
593+
@app.callback(Output("out", "children"), [Input("persisted", "value")])
594+
def set_out(val):
595+
return val
596+
597+
dash_duo.start_server(app)
598+
599+
dash_duo.wait_for_text_to_equal("#out", "")
600+
601+
dash_duo.find_element("#persistence-key").send_keys("a")
602+
time.sleep(0.2)
603+
assert not dash_duo.get_logs()
604+
dash_duo.wait_for_text_to_equal("#out", "")
605+
dash_duo.find_element("#persistence-val").send_keys("alpaca")
606+
dash_duo.wait_for_text_to_equal("#out", "alpaca")
607+
608+
dash_duo.find_element("#persistence-key").send_keys("b")
609+
dash_duo.wait_for_text_to_equal("#out", "")
610+
dash_duo.clear_input("#persistence-val")
611+
dash_duo.find_element("#persistence-val").send_keys("artichoke")
612+
dash_duo.wait_for_text_to_equal("#out", "artichoke")
613+
614+
# no persistence, still goes back to original value
615+
dash_duo.clear_input("#persistence-key")
616+
dash_duo.wait_for_text_to_equal("#out", "")
617+
618+
# apricot and artichoke saved
619+
dash_duo.find_element("#persistence-key").send_keys("a")
620+
dash_duo.wait_for_text_to_equal("#out", "alpaca")
621+
dash_duo.find_element("#persistence-key").send_keys("b")
622+
assert not dash_duo.get_logs()
623+
dash_duo.wait_for_text_to_equal("#out", "artichoke")

0 commit comments

Comments
 (0)