|
| 1 | +from dash import dcc, html, Input, Output, Patch, Dash |
| 2 | + |
| 3 | +from dash.testing.wait import until |
| 4 | + |
| 5 | + |
| 6 | +def test_dcl001_descendant_tabs(dash_duo): |
| 7 | + app = Dash() |
| 8 | + |
| 9 | + app.layout = html.Div( |
| 10 | + [ |
| 11 | + html.Button("Enable Tabs", id="button", n_clicks=0), |
| 12 | + html.Button("Add Tabs", id="add_button", n_clicks=0), |
| 13 | + dcc.Store(id="store-data", data=None), |
| 14 | + dcc.Tabs( |
| 15 | + [ |
| 16 | + dcc.Tab(label="Tab A", value="tab-a", id="tab-a", disabled=True), |
| 17 | + dcc.Tab(label="Tab B", value="tab-b", id="tab-b", disabled=True), |
| 18 | + ], |
| 19 | + id="tabs", |
| 20 | + value="tab-a", |
| 21 | + ), |
| 22 | + ] |
| 23 | + ) |
| 24 | + |
| 25 | + @app.callback(Output("store-data", "data"), Input("button", "n_clicks")) |
| 26 | + def update_store_data(clicks): |
| 27 | + if clicks > 0: |
| 28 | + return {"data": "available"} |
| 29 | + return None |
| 30 | + |
| 31 | + @app.callback( |
| 32 | + Output("tabs", "children"), |
| 33 | + Input("add_button", "n_clicks"), |
| 34 | + prevent_initial_call=True, |
| 35 | + ) |
| 36 | + def add_tabs(n): |
| 37 | + children = Patch() |
| 38 | + children.append(dcc.Tab(label=f"{n}", value=f"{n}", id=f"test-{n}")) |
| 39 | + return children |
| 40 | + |
| 41 | + @app.callback( |
| 42 | + Output("tab-a", "disabled"), |
| 43 | + Output("tab-b", "disabled"), |
| 44 | + Input("store-data", "data"), |
| 45 | + ) |
| 46 | + def toggle_tabs(store_data): |
| 47 | + if store_data is not None and "data" in store_data: |
| 48 | + return False, False |
| 49 | + return True, True |
| 50 | + |
| 51 | + dash_duo.start_server(app) |
| 52 | + dash_duo.wait_for_text_to_equal("#button", f"Enable Tabs") |
| 53 | + dash_duo.find_element("#tab-a.tab--disabled") |
| 54 | + dash_duo.find_element("#button").click() |
| 55 | + dash_duo.find_element("#tab-a:not(.tab--disabled)") |
| 56 | + dash_duo.find_element("#add_button").click() |
| 57 | + dash_duo.find_element("#test-1:not(.tab--disabled)") |
0 commit comments