|
| 1 | +import time |
| 2 | +from dash import Dash, Input, Output, html |
| 3 | +import json |
| 4 | + |
| 5 | +import dash_test_components as dt |
| 6 | + |
| 7 | + |
| 8 | +def test_rtype001_rendertype(dash_duo): |
| 9 | + app = Dash() |
| 10 | + |
| 11 | + app.layout = html.Div( |
| 12 | + [ |
| 13 | + html.Div( |
| 14 | + dt.RenderType(id="render_test"), |
| 15 | + id="container", |
| 16 | + ), |
| 17 | + html.Button("redraw", id="redraw"), |
| 18 | + html.Button("update render", id="update_render"), |
| 19 | + html.Button("clientside", id="clientside_render"), |
| 20 | + html.Div(id="render_output"), |
| 21 | + ] |
| 22 | + ) |
| 23 | + |
| 24 | + app.clientside_callback( |
| 25 | + """(n) => { |
| 26 | + dash_clientside.set_props('render_test', {n_clicks: 20}) |
| 27 | + }""", |
| 28 | + Input("clientside_render", "n_clicks"), |
| 29 | + ) |
| 30 | + |
| 31 | + @app.callback( |
| 32 | + Output("container", "children"), |
| 33 | + Input("redraw", "n_clicks"), |
| 34 | + prevent_initial_call=True, |
| 35 | + ) |
| 36 | + def on_click(_): |
| 37 | + return dt.RenderType(id="render_test") |
| 38 | + |
| 39 | + @app.callback( |
| 40 | + Output("render_test", "n_clicks"), |
| 41 | + Input("update_render", "n_clicks"), |
| 42 | + prevent_initial_call=True, |
| 43 | + ) |
| 44 | + def update_render(_): |
| 45 | + return 0 |
| 46 | + |
| 47 | + @app.callback(Output("render_output", "children"), Input("render_test", "n_clicks")) |
| 48 | + def display_clicks(n): |
| 49 | + return json.dumps(n) |
| 50 | + |
| 51 | + dash_duo.start_server(app) |
| 52 | + |
| 53 | + render_type = "#render_test > span" |
| 54 | + render_output = "#render_output" |
| 55 | + dash_duo.wait_for_text_to_equal(render_type, "parent") |
| 56 | + dash_duo.find_element("#update_render").click() |
| 57 | + dash_duo.wait_for_text_to_equal(render_type, "callback") |
| 58 | + dash_duo.wait_for_text_to_equal(render_output, "0") |
| 59 | + dash_duo.find_element("#clientside_render").click() |
| 60 | + dash_duo.wait_for_text_to_equal(render_type, "clientsideApi") |
| 61 | + dash_duo.wait_for_text_to_equal(render_output, "20") |
| 62 | + dash_duo.find_element("#render_test > button").click() |
| 63 | + dash_duo.wait_for_text_to_equal(render_type, "internal") |
| 64 | + dash_duo.wait_for_text_to_equal(render_output, "21") |
| 65 | + dash_duo.find_element("#redraw").click() |
| 66 | + dash_duo.wait_for_text_to_equal(render_type, "parent") |
| 67 | + dash_duo.wait_for_text_to_equal(render_output, "null") |
0 commit comments