|
1 | 1 | # -*- coding: UTF-8 -*-
|
2 | 2 | from multiprocessing import Value, Lock
|
3 |
| -import pytest |
4 | 3 |
|
5 | 4 | from dash import Dash, Input, Output, State, ClientsideFunction, ALL, html, dcc
|
6 | 5 | from selenium.webdriver.common.keys import Keys
|
@@ -224,31 +223,6 @@ def test_clsd004_clientside_multiple_outputs(dash_duo):
|
224 | 223 | dash_duo.wait_for_text_to_equal(selector, expected)
|
225 | 224 |
|
226 | 225 |
|
227 |
| -@pytest.mark.xfail(reason="Promises are now handled within Dash-Renderer") |
228 |
| -def test_clsd005_clientside_fails_when_returning_a_promise(dash_duo): |
229 |
| - app = Dash(__name__, assets_folder="assets") |
230 |
| - |
231 |
| - app.layout = html.Div( |
232 |
| - [ |
233 |
| - html.Div(id="input", children="hello"), |
234 |
| - html.Div(id="side-effect"), |
235 |
| - html.Div(id="output", children="output"), |
236 |
| - ] |
237 |
| - ) |
238 |
| - |
239 |
| - app.clientside_callback( |
240 |
| - ClientsideFunction("clientside", "side_effect_and_return_a_promise"), |
241 |
| - Output("output", "children"), |
242 |
| - [Input("input", "children")], |
243 |
| - ) |
244 |
| - |
245 |
| - dash_duo.start_server(app) |
246 |
| - |
247 |
| - dash_duo.wait_for_text_to_equal("#input", "hello") |
248 |
| - dash_duo.wait_for_text_to_equal("#side-effect", "side effect") |
249 |
| - dash_duo.wait_for_text_to_equal("#output", "output") |
250 |
| - |
251 |
| - |
252 | 226 | def test_clsd006_PreventUpdate(dash_duo):
|
253 | 227 | app = Dash(__name__, assets_folder="assets")
|
254 | 228 |
|
@@ -805,3 +779,53 @@ def callback(value):
|
805 | 779 | dash_duo.wait_for_text_to_equal("#clientside-div", "clientside-initial")
|
806 | 780 | lock.release()
|
807 | 781 | dash_duo.wait_for_text_to_equal("#serverside-div", "serverside-initial-deferred")
|
| 782 | + |
| 783 | + |
| 784 | +def test_clsd018_clientside_inline_async_function(dash_duo): |
| 785 | + app = Dash(__name__) |
| 786 | + |
| 787 | + app.layout = html.Div( |
| 788 | + [ |
| 789 | + html.Div(id="input", children=["initial"]), |
| 790 | + html.Div(id="output-div"), |
| 791 | + ] |
| 792 | + ) |
| 793 | + |
| 794 | + app.clientside_callback( |
| 795 | + """ |
| 796 | + async function(input) { |
| 797 | + return input + "-inline"; |
| 798 | + } |
| 799 | + """, |
| 800 | + Output("output-div", "children"), |
| 801 | + Input("input", "children"), |
| 802 | + ) |
| 803 | + |
| 804 | + dash_duo.start_server(app) |
| 805 | + dash_duo.wait_for_text_to_equal("#output-div", "initial-inline") |
| 806 | + |
| 807 | + |
| 808 | +def test_clsd019_clientside_inline_promise(dash_duo): |
| 809 | + app = Dash(__name__) |
| 810 | + |
| 811 | + app.layout = html.Div( |
| 812 | + [ |
| 813 | + html.Div(id="input", children=["initial"]), |
| 814 | + html.Div(id="output-div"), |
| 815 | + ] |
| 816 | + ) |
| 817 | + |
| 818 | + app.clientside_callback( |
| 819 | + """ |
| 820 | + function(inputValue) { |
| 821 | + return new Promise(function (resolve) { |
| 822 | + resolve(inputValue + "-inline"); |
| 823 | + }); |
| 824 | + } |
| 825 | + """, |
| 826 | + Output("output-div", "children"), |
| 827 | + Input("input", "children"), |
| 828 | + ) |
| 829 | + |
| 830 | + dash_duo.start_server(app) |
| 831 | + dash_duo.wait_for_text_to_equal("#output-div", "initial-nline") |
0 commit comments