|
| 1 | +from dash import Dash, html, Input, Output |
| 2 | +import dash_test_components as dt |
| 3 | +import dash_generator_test_component_standard as dgs |
| 4 | + |
| 5 | + |
| 6 | +def test_rblib001_dynamic_loading(dash_duo): |
| 7 | + app = Dash(__name__) |
| 8 | + |
| 9 | + app.layout = html.Div( |
| 10 | + [ |
| 11 | + html.Button("Insert", id="insert-btn"), |
| 12 | + html.Div(id="output"), |
| 13 | + dgs.MyStandardComponent(id="dgs"), |
| 14 | + ] |
| 15 | + ) |
| 16 | + |
| 17 | + @app.callback( |
| 18 | + Output("output", "children"), |
| 19 | + [Input("insert-btn", "n_clicks")], |
| 20 | + prevent_initial_call=True, |
| 21 | + ) |
| 22 | + def update_output(_): |
| 23 | + import dash_generator_test_component_nested as dn |
| 24 | + |
| 25 | + return [ |
| 26 | + dt.StyledComponent(value="Styled", id="styled"), |
| 27 | + dn.MyNestedComponent(value="nested", id="nested"), |
| 28 | + ] |
| 29 | + |
| 30 | + dash_duo.start_server(app) |
| 31 | + |
| 32 | + def assert_unloaded(namespace): |
| 33 | + assert dash_duo.driver.execute_script( |
| 34 | + f"return window['{namespace}'] === undefined" |
| 35 | + ) |
| 36 | + |
| 37 | + def assert_loaded(namespace): |
| 38 | + assert dash_duo.driver.execute_script( |
| 39 | + f"return window['{namespace}'] !== undefined" |
| 40 | + ) |
| 41 | + |
| 42 | + assert_unloaded(dt.package_name) |
| 43 | + assert_unloaded(dgs.package_name) |
| 44 | + assert_unloaded("dash_generator_test_component_nested") |
| 45 | + dash_duo.wait_for_element("#dgs") |
| 46 | + assert_unloaded(dt.package_name) |
| 47 | + assert_loaded(dgs.package_name) |
| 48 | + |
| 49 | + dash_duo.wait_for_element("#insert-btn").click() |
| 50 | + |
| 51 | + dash_duo.wait_for_element("#styled") |
| 52 | + assert_loaded(dt.package_name) |
| 53 | + assert_loaded("dash_generator_test_component_nested") |
0 commit comments