|
2 | 2 | import re
|
3 | 3 | from selenium.webdriver.common.keys import Keys
|
4 | 4 | import json
|
| 5 | +import time |
5 | 6 |
|
6 | 7 | from dash.testing import wait
|
7 | 8 | import dash
|
@@ -552,3 +553,65 @@ def update_selected_values(values):
|
552 | 553 | dash_duo.wait_for_text_to_equal(
|
553 | 554 | "#selected-values", "['option0-2', 'option1-2', 'option2-2']"
|
554 | 555 | )
|
| 556 | + |
| 557 | + |
| 558 | +def test_cbwc008_running_match(dash_duo): |
| 559 | + app = dash.Dash() |
| 560 | + |
| 561 | + app.layout = [ |
| 562 | + html.Div( |
| 563 | + [ |
| 564 | + html.Button( |
| 565 | + "Test1", |
| 566 | + id={"component": "button", "index": "1"}, |
| 567 | + ), |
| 568 | + html.Button( |
| 569 | + "Test2", |
| 570 | + id={"component": "button", "index": "2"}, |
| 571 | + ), |
| 572 | + ], |
| 573 | + id="buttons", |
| 574 | + ), |
| 575 | + html.Div(html.Div(id={"component": "output", "index": "1"}), id="output1"), |
| 576 | + html.Div(html.Div(id={"component": "output", "index": "2"}), id="output2"), |
| 577 | + ] |
| 578 | + |
| 579 | + @app.callback( |
| 580 | + Output({"component": "output", "index": MATCH}, "children"), |
| 581 | + Input({"component": "button", "index": MATCH}, "n_clicks"), |
| 582 | + running=[ |
| 583 | + ( |
| 584 | + Output({"component": "button", "index": MATCH}, "children"), |
| 585 | + "running", |
| 586 | + "finished", |
| 587 | + ), |
| 588 | + (Output({"component": "button", "index": ALL}, "disabled"), True, False), |
| 589 | + ], |
| 590 | + prevent_initial_call=True, |
| 591 | + ) |
| 592 | + def on_click(_) -> str: |
| 593 | + time.sleep(1) |
| 594 | + return "done" |
| 595 | + |
| 596 | + dash_duo.start_server(app) |
| 597 | + |
| 598 | + for i in range(1, 3): |
| 599 | + dash_duo.find_element(f"#buttons button:nth-child({i})").click() |
| 600 | + dash_duo.wait_for_text_to_equal(f"#buttons button:nth-child({i})", "running") |
| 601 | + # verify all the buttons were disabled. |
| 602 | + assert dash_duo.find_element("#buttons button:nth-child(1)").get_attribute( |
| 603 | + "disabled" |
| 604 | + ) |
| 605 | + assert dash_duo.find_element("#buttons button:nth-child(2)").get_attribute( |
| 606 | + "disabled" |
| 607 | + ) |
| 608 | + |
| 609 | + dash_duo.wait_for_text_to_equal(f"#output{i}", "done") |
| 610 | + dash_duo.wait_for_text_to_equal(f"#buttons button:nth-child({i})", "finished") |
| 611 | + |
| 612 | + assert not dash_duo.find_element("#buttons button:nth-child(1)").get_attribute( |
| 613 | + "disabled" |
| 614 | + ) |
| 615 | + assert not dash_duo.find_element("#buttons button:nth-child(2)").get_attribute( |
| 616 | + "disabled" |
| 617 | + ) |
0 commit comments