Skip to content

Commit

Permalink
Test clipboard to respond to new content directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxstr committed Oct 3, 2023
1 parent c074cbb commit 262c621
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dash import Dash, html, dcc
from dash import Dash, html, dcc, callback, Output, Input

import dash.testing.wait as wait
import time
Expand Down Expand Up @@ -54,3 +54,32 @@ def test_clp002_clipboard_text(dash_dcc_headed):
== copy_text,
timeout=3,
)

def test_clp003_clipboard_text(dash_dcc_headed):
copy_text = "Copy this text to the clipboard using a separate button"
app = Dash(__name__, prevent_initial_callbacks=True)
app.layout = html.Div(
[dcc.Clipboard(id="copy_icon", content=copy_text), dcc.Textarea(id="paste"), html.Button("Copy", id="copy_button")]
)
@callback(
Output("copy_icon", "content"),
Input("copy_button", "n_clicks"),
prevent_initial_call=True,
)
def selected(clicks):
return f"{clicks}"

dash_dcc_headed.start_server(app)

dash_dcc_headed.find_element("#copy_button").click()
time.sleep(1)
dash_dcc_headed.find_element("#paste").click()
ActionChains(dash_dcc_headed.driver).key_down(Keys.CONTROL).send_keys("v").key_up(
Keys.CONTROL
).perform()

wait.until(
lambda: dash_dcc_headed.find_element("#paste").get_attribute("value")
== copy_text,
timeout=3,
)

0 comments on commit 262c621

Please sign in to comment.