import dash
import dash_core_components as dcc
import dash_html_components as html
import dash.testing.wait as wait
import time


from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys


def test_clp001_clipboard_text(dash_dcc_headed):
    copy_text = "Hello, Dash!"
    app = dash.Dash(__name__, prevent_initial_callbacks=True)
    app.layout = html.Div(
        [
            html.Div(copy_text, id="copy1"),
            dcc.Clipboard(id="copy_icon1", target_id="copy1"),
            dcc.Textarea(id="paste1"),
        ]
    )
    dash_dcc_headed.start_server(app)
    dash_dcc_headed.driver.execute_script("navigator.clipboard.writeText('')")

    dash_dcc_headed.find_element("#copy_icon1").click()
    time.sleep(2)
    dash_dcc_headed.find_element("#paste1").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("#paste1").get_attribute("value")
        == copy_text,
        timeout=3,
    )


def test_clp002_clipboard_text(dash_dcc_headed):
    copy_text = "Copy this text to the clipboard"
    app = dash.Dash(__name__, prevent_initial_callbacks=True)
    app.layout = html.Div(
        [dcc.Clipboard(id="copy_icon2", text=copy_text), dcc.Textarea(id="paste2")]
    )
    dash_dcc_headed.start_server(app)
    dash_dcc_headed.driver.execute_script("navigator.clipboard.writeText('')")

    dash_dcc_headed.find_element("#copy_icon2").click()
    time.sleep(2)
    dash_dcc_headed.find_element("#paste2").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("#paste2").get_attribute("value")
        == copy_text,
        timeout=3,
    )

@@ -449,33 +449,32 @@
 y_text, id=%22copy
-1
 %22),%0A            
@@ -500,17 +500,16 @@
 opy_icon
-1
 %22, targe
@@ -518,17 +518,16 @@
 id=%22copy
-1
 %22),%0A    
@@ -556,17 +556,16 @@
 d=%22paste
-1
 %22),%0A    
@@ -617,87 +617,8 @@
 app)
-%0A    dash_dcc_headed.driver.execute_script(%22navigator.clipboard.writeText('')%22)
 %0A%0A  
@@ -659,17 +659,16 @@
 opy_icon
-1
 %22).click
@@ -664,32 +664,35 @@
 con%22).click()%0A  
+  #
   time.sleep(2)%0A
@@ -731,17 +731,16 @@
 (%22#paste
-1
 %22).click
@@ -935,17 +935,16 @@
 (%22#paste
-1
 %22).get_a
@@ -1234,17 +1234,16 @@
 opy_icon
-2
 %22, text=
@@ -1276,17 +1276,16 @@
 d=%22paste
-2
 %22)%5D%0A    
@@ -1327,87 +1327,8 @@
 app)
-%0A    dash_dcc_headed.driver.execute_script(%22navigator.clipboard.writeText('')%22)
 %0A%0A  
@@ -1369,17 +1369,16 @@
 opy_icon
-2
 %22).click
@@ -1387,33 +1387,33 @@
 %0A    time.sleep(
-2
+1
 )%0A    dash_dcc_h
@@ -1438,17 +1438,16 @@
 (%22#paste
-2
 %22).click
@@ -1642,17 +1642,16 @@
 (%22#paste
-2
 %22).get_a

test cleanup