(
dash_duo, kwargs, expected_update_title, clientside_title
)
| 181 | ], |
| 182 | ) |
| 183 | def test_rdls003_update_title( |
| 184 | dash_duo, kwargs, expected_update_title, clientside_title |
| 185 | ): |
| 186 | app = Dash("Dash", **kwargs) |
| 187 | lock = Lock() |
| 188 | |
| 189 | app.layout = html.Div( |
| 190 | children=[ |
| 191 | html.H3("Press button see document title updating"), |
| 192 | html.Div(id="output"), |
| 193 | html.Button("Update", id="button", n_clicks=0), |
| 194 | html.Button("Update Page", id="page", n_clicks=0), |
| 195 | html.Div(id="dummy"), |
| 196 | ] |
| 197 | ) |
| 198 | if clientside_title: |
| 199 | app.clientside_callback( |
| 200 | """ |
| 201 | function(n_clicks) { |
| 202 | document.title = 'Page ' + n_clicks; |
| 203 | return 'Page ' + n_clicks; |
| 204 | } |
| 205 | """, |
| 206 | Output("dummy", "children"), |
| 207 | [Input("page", "n_clicks")], |
| 208 | ) |
| 209 | |
| 210 | @app.callback(Output("output", "children"), [Input("button", "n_clicks")]) |
| 211 | def update(n): |
| 212 | with lock: |
| 213 | return n |
| 214 | |
| 215 | with lock: |
| 216 | dash_duo.start_server(app) |
| 217 | # check for update-title during startup |
| 218 | # the clientside callback isn't blocking so it may update the title |
| 219 | if not clientside_title: |
| 220 | until(lambda: dash_duo.driver.title == expected_update_title, timeout=1) |
| 221 | |
| 222 | # check for original title after loading |
| 223 | until( |
| 224 | lambda: dash_duo.driver.title == "Page 0" if clientside_title else "Dash", |
| 225 | timeout=1, |
| 226 | ) |
| 227 | |
| 228 | with lock: |
| 229 | dash_duo.find_element("#button").click() |
| 230 | # check for update-title while processing callback |
| 231 | if clientside_title and not kwargs.get("update_title", True): |
| 232 | until(lambda: dash_duo.driver.title == "Page 0", timeout=1) |
| 233 | else: |
| 234 | until(lambda: dash_duo.driver.title == expected_update_title, timeout=1) |
| 235 | |
| 236 | if clientside_title: |
| 237 | dash_duo.find_element("#page").click() |
| 238 | dash_duo.wait_for_text_to_equal("#dummy", "Page 1") |
| 239 | until(lambda: dash_duo.driver.title == "Page 1", timeout=1) |
| 240 |
nothing calls this directly
no test coverage detected
searching dependent graphs…