|
6 | 6 | import dash_html_components as html |
7 | 7 | import dash_core_components as dcc |
8 | 8 | import dash |
| 9 | +from dash.testing import wait |
9 | 10 | from dash.dependencies import Input, Output, State, ALL, ALLSMALLER, MATCH |
10 | 11 |
|
11 | 12 |
|
@@ -229,7 +230,17 @@ def assert_item(item, text, done, prefix="", suffix=""): |
229 | 230 | assert_count(0) |
230 | 231 |
|
231 | 232 |
|
| 233 | +fibonacci_count = 0 |
| 234 | +fibonacci_sum_count = 0 |
| 235 | + |
| 236 | + |
232 | 237 | def fibonacci_app(clientside): |
| 238 | + global fibonacci_count |
| 239 | + global fibonacci_sum_count |
| 240 | + |
| 241 | + fibonacci_count = 0 |
| 242 | + fibonacci_sum_count = 0 |
| 243 | + |
233 | 244 | # This app tests 2 things in particular: |
234 | 245 | # - clientside callbacks work the same as server-side |
235 | 246 | # - callbacks using ALLSMALLER as an input to MATCH of the exact same id/prop |
@@ -275,12 +286,20 @@ def items(n): |
275 | 286 | Output({"i": MATCH}, "children"), [Input({"i": ALLSMALLER}, "children")] |
276 | 287 | ) |
277 | 288 | def sequence(prev): |
| 289 | + global fibonacci_count |
| 290 | + fibonacci_count = fibonacci_count + 1 |
| 291 | + print(fibonacci_count) |
| 292 | + |
278 | 293 | if len(prev) < 2: |
279 | 294 | return len(prev) |
280 | 295 | return int(prev[-1] or 0) + int(prev[-2] or 0) |
281 | 296 |
|
282 | 297 | @app.callback(Output("sum", "children"), [Input({"i": ALL}, "children")]) |
283 | 298 | def show_sum(seq): |
| 299 | + global fibonacci_sum_count |
| 300 | + fibonacci_sum_count = fibonacci_sum_count + 1 |
| 301 | + print("fibonacci_sum_count: ", fibonacci_sum_count) |
| 302 | + |
284 | 303 | return "{} elements, sum: {}".format( |
285 | 304 | len(seq), sum(int(v or 0) for v in seq) |
286 | 305 | ) |
@@ -454,3 +473,46 @@ def update_output_on_page_pattern(value): |
454 | 473 | trigger_text = 'triggered is Truthy with prop_ids {"index":1,"type":"input"}.value' |
455 | 474 | dash_duo.wait_for_text_to_equal("#output-outer", trigger_text) |
456 | 475 | dash_duo.wait_for_text_to_equal("#output-inner", trigger_text) |
| 476 | + |
| 477 | + |
| 478 | +def test_cbwc005_callbacks_count(dash_duo): |
| 479 | + global fibonacci_count |
| 480 | + global fibonacci_sum_count |
| 481 | + |
| 482 | + app = fibonacci_app(False) |
| 483 | + dash_duo.start_server(app) |
| 484 | + |
| 485 | + wait.until(lambda: fibonacci_count == 4, 3) # initial |
| 486 | + wait.until(lambda: fibonacci_sum_count == 2, 3) # initial + triggered |
| 487 | + |
| 488 | + dash_duo.find_element("#n").send_keys(Keys.UP) # 5 |
| 489 | + wait.until(lambda: fibonacci_count == 9, 3) |
| 490 | + wait.until(lambda: fibonacci_sum_count == 3, 3) |
| 491 | + |
| 492 | + dash_duo.find_element("#n").send_keys(Keys.UP) # 6 |
| 493 | + wait.until(lambda: fibonacci_count == 15, 3) |
| 494 | + wait.until(lambda: fibonacci_sum_count == 4, 3) |
| 495 | + |
| 496 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 5 |
| 497 | + wait.until(lambda: fibonacci_count == 20, 3) |
| 498 | + wait.until(lambda: fibonacci_sum_count == 5, 3) |
| 499 | + |
| 500 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 4 |
| 501 | + wait.until(lambda: fibonacci_count == 24, 3) |
| 502 | + wait.until(lambda: fibonacci_sum_count == 6, 3) |
| 503 | + |
| 504 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 3 |
| 505 | + wait.until(lambda: fibonacci_count == 27, 3) |
| 506 | + wait.until(lambda: fibonacci_sum_count == 7, 3) |
| 507 | + |
| 508 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 2 |
| 509 | + wait.until(lambda: fibonacci_count == 29, 3) |
| 510 | + wait.until(lambda: fibonacci_sum_count == 8, 3) |
| 511 | + |
| 512 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 1 |
| 513 | + wait.until(lambda: fibonacci_count == 30, 3) |
| 514 | + wait.until(lambda: fibonacci_sum_count == 9, 3) |
| 515 | + |
| 516 | + dash_duo.find_element("#n").send_keys(Keys.DOWN) # 0 |
| 517 | + wait.until(lambda: fibonacci_count == 30, 3) |
| 518 | + wait.until(lambda: fibonacci_sum_count == 10, 3) |
0 commit comments