Skip to content

Commit 7da11f6

Browse files
add clientside input/output callback test
1 parent 4a6b934 commit 7da11f6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/integration/clientside/assets/clientside.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,22 @@ window.dash_clientside.clientside = {
8181

8282
states_list_to_str: function(val0, val1, st0, st1) {
8383
return JSON.stringify(dash_clientside.callback_context.states_list);
84+
},
85+
86+
input_output_callback: function(inputValue) {
87+
const triggered = dash_clientside.callback_context.triggered;
88+
if (triggered.length==0){
89+
return inputValue;
90+
} else {
91+
return inputValue + 1;
92+
}
93+
},
94+
95+
input_output_follower: function(inputValue) {
96+
if (!window.callCount) {
97+
window.callCount = 0
98+
}
99+
window.callCount += 1;
100+
return inputValue.toString();
84101
}
85102
};

tests/integration/clientside/test_clientside.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,37 @@ def test_clsd013_clientside_callback_context_states_list(dash_duo):
683683
'{"id":{"in1":2},"property":"value","value":"test 2"}]]'
684684
),
685685
)
686+
687+
688+
def test_clsd014_input_output_callback(dash_duo):
689+
app = Dash(__name__, assets_folder="assets")
690+
691+
app.layout = html.Div(
692+
[html.Div(id="input-text"), dcc.Input(id="input", type="number", value=0)]
693+
)
694+
695+
app.clientside_callback(
696+
ClientsideFunction(
697+
namespace="clientside", function_name="input_output_callback"
698+
),
699+
Output("input", "value"),
700+
Input("input", "value"),
701+
)
702+
703+
app.clientside_callback(
704+
ClientsideFunction(
705+
namespace="clientside", function_name="input_output_follower"
706+
),
707+
Output("input-text", "children"),
708+
Input("input", "value"),
709+
)
710+
711+
dash_duo.start_server(app)
712+
713+
dash_duo.find_element("#input").send_keys("2")
714+
dash_duo.wait_for_text_to_equal("#input-text", "3")
715+
call_count = dash_duo.driver.execute_script("return window.callCount;")
716+
717+
assert call_count == 2, "initial + changed once"
718+
719+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)