|
4 | 4 | import dash_html_components as html
|
5 | 5 | import dash_core_components as dcc
|
6 | 6 | from dash import Dash
|
7 |
| -from dash.dependencies import Input, Output, ClientsideFunction |
| 7 | +from dash.dependencies import Input, Output, State, ClientsideFunction |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def test_clsd001_simple_clientside_serverside_callback(dash_duo):
|
@@ -261,3 +261,86 @@ def test_clsd005_clientside_fails_when_returning_a_promise(dash_duo):
|
261 | 261 | dash_duo.wait_for_text_to_equal("#input", "hello")
|
262 | 262 | dash_duo.wait_for_text_to_equal("#side-effect", "side effect")
|
263 | 263 | dash_duo.wait_for_text_to_equal("#output", "output")
|
| 264 | + |
| 265 | + |
| 266 | +def test_clsd006_PreventUpdate(dash_duo): |
| 267 | + app = Dash(__name__, assets_folder="assets") |
| 268 | + |
| 269 | + app.layout = html.Div( |
| 270 | + [ |
| 271 | + dcc.Input(id="first", value=1), |
| 272 | + dcc.Input(id="second", value=1), |
| 273 | + dcc.Input(id="third", value=1) |
| 274 | + ] |
| 275 | + ) |
| 276 | + |
| 277 | + app.clientside_callback( |
| 278 | + ClientsideFunction(namespace="clientside", function_name="add1_prevent_at_11"), |
| 279 | + Output("second", "value"), |
| 280 | + [Input("first", "value")], |
| 281 | + [State("second", "value")] |
| 282 | + ) |
| 283 | + |
| 284 | + app.clientside_callback( |
| 285 | + ClientsideFunction(namespace="clientside", function_name="add1_prevent_at_11"), |
| 286 | + Output("third", "value"), |
| 287 | + [Input("second", "value")], |
| 288 | + [State("third", "value")] |
| 289 | + ) |
| 290 | + |
| 291 | + dash_duo.start_server(app) |
| 292 | + |
| 293 | + dash_duo.wait_for_text_to_equal("#first", '1') |
| 294 | + dash_duo.wait_for_text_to_equal("#second", '2') |
| 295 | + dash_duo.wait_for_text_to_equal("#third", '2') |
| 296 | + |
| 297 | + dash_duo.find_element("#first").send_keys("1") |
| 298 | + |
| 299 | + dash_duo.wait_for_text_to_equal("#first", '11') |
| 300 | + dash_duo.wait_for_text_to_equal("#second", '2') |
| 301 | + dash_duo.wait_for_text_to_equal("#third", '2') |
| 302 | + |
| 303 | + dash_duo.find_element("#first").send_keys("1") |
| 304 | + |
| 305 | + dash_duo.wait_for_text_to_equal("#first", '111') |
| 306 | + dash_duo.wait_for_text_to_equal("#second", '3') |
| 307 | + dash_duo.wait_for_text_to_equal("#third", '3') |
| 308 | + |
| 309 | + |
| 310 | +def test_clsd006_no_update(dash_duo): |
| 311 | + app = Dash(__name__, assets_folder="assets") |
| 312 | + |
| 313 | + app.layout = html.Div( |
| 314 | + [ |
| 315 | + dcc.Input(id="first", value=1), |
| 316 | + dcc.Input(id="second", value=1), |
| 317 | + dcc.Input(id="third", value=1) |
| 318 | + ] |
| 319 | + ) |
| 320 | + |
| 321 | + app.clientside_callback( |
| 322 | + ClientsideFunction(namespace="clientside", function_name="add1_no_update_at_11"), |
| 323 | + [Output("second", "value"), |
| 324 | + Output("third", "value")], |
| 325 | + [Input("first", "value")], |
| 326 | + [State("second", "value"), |
| 327 | + State("third", "value")] |
| 328 | + ) |
| 329 | + |
| 330 | + dash_duo.start_server(app) |
| 331 | + |
| 332 | + dash_duo.wait_for_text_to_equal("#first", '1') |
| 333 | + dash_duo.wait_for_text_to_equal("#second", '2') |
| 334 | + dash_duo.wait_for_text_to_equal("#third", '2') |
| 335 | + |
| 336 | + dash_duo.find_element("#first").send_keys("1") |
| 337 | + |
| 338 | + dash_duo.wait_for_text_to_equal("#first", '11') |
| 339 | + dash_duo.wait_for_text_to_equal("#second", '2') |
| 340 | + dash_duo.wait_for_text_to_equal("#third", '3') |
| 341 | + |
| 342 | + dash_duo.find_element("#first").send_keys("1") |
| 343 | + |
| 344 | + dash_duo.wait_for_text_to_equal("#first", '111') |
| 345 | + dash_duo.wait_for_text_to_equal("#second", '3') |
| 346 | + dash_duo.wait_for_text_to_equal("#third", '4') |
0 commit comments