Skip to content

Commit 73747c8

Browse files
committed
Test clipboard to respond to new content directly
1 parent b9c9270 commit 73747c8

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

components/dash-core-components/tests/integration/clipboard/test_clipboard.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dash import Dash, html, dcc
1+
from dash import Dash, html, dcc, callback, Output, Input
22

33
import dash.testing.wait as wait
44
import time
@@ -54,3 +54,32 @@ def test_clp002_clipboard_text(dash_dcc_headed):
5454
== copy_text,
5555
timeout=3,
5656
)
57+
58+
def test_clp003_clipboard_text(dash_dcc_headed):
59+
copy_text = "Copy this text to the clipboard using a separate button"
60+
app = Dash(__name__, prevent_initial_callbacks=True)
61+
app.layout = html.Div(
62+
[dcc.Clipboard(id="copy_icon", content=copy_text), dcc.Textarea(id="paste"), html.Button("Copy", id="copy_button")]
63+
)
64+
@callback(
65+
Output("copy_icon", "content"),
66+
Input("copy_button", "n_clicks"),
67+
prevent_initial_call=True,
68+
)
69+
def selected(clicks):
70+
return f"{clicks}"
71+
72+
dash_dcc_headed.start_server(app)
73+
74+
dash_dcc_headed.find_element("#copy_button").click()
75+
time.sleep(1)
76+
dash_dcc_headed.find_element("#paste").click()
77+
ActionChains(dash_dcc_headed.driver).key_down(Keys.CONTROL).send_keys("v").key_up(
78+
Keys.CONTROL
79+
).perform()
80+
81+
wait.until(
82+
lambda: dash_dcc_headed.find_element("#paste").get_attribute("value")
83+
== copy_text,
84+
timeout=3,
85+
)

0 commit comments

Comments
 (0)