-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathtest_debounce.py
56 lines (44 loc) · 2.02 KB
/
test_debounce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
import pytest
def test_debounce_text_by_time(dash_dcc, debounce_text_app):
dash_dcc.start_server(debounce_text_app)
# expect that a long debounce does not call back in a short amount of time
elem = dash_dcc.find_element("#input-slow")
elem.send_keys("unit test slow")
with pytest.raises(TimeoutException):
WebDriverWait(dash_dcc.driver, timeout=1).until(
lambda d: d.find_element(By.XPATH, "//*[text()='unit test slow']")
)
# but do expect that it is eventually called
dash_dcc.wait_for_text_to_equal(
"#div-slow", "unit test slow"
), "long debounce is eventually called back"
# expect that a short debounce calls back within a short amount of time
elem = dash_dcc.find_element("#input-fast")
elem.send_keys("unit test fast")
WebDriverWait(dash_dcc.driver, timeout=1).until(
lambda d: d.find_element(By.XPATH, "//*[text()='unit test fast']")
)
assert dash_dcc.get_logs() == []
def test_debounce_number_by_time(dash_dcc, debounce_number_app):
dash_dcc.start_server(debounce_number_app)
# expect that a long debounce does not call back in a short amount of time
elem = dash_dcc.find_element("#input-slow")
elem.send_keys("12345")
with pytest.raises(TimeoutException):
WebDriverWait(dash_dcc.driver, timeout=1).until(
lambda d: d.find_element(By.XPATH, "//*[text()='12345']")
)
# but do expect that it is eventually called
dash_dcc.wait_for_text_to_equal(
"#div-slow", "12345"
), "long debounce is eventually called back"
# expect that a short debounce calls back within a short amount of time
elem = dash_dcc.find_element("#input-fast")
elem.send_keys("10000")
WebDriverWait(dash_dcc.driver, timeout=1).until(
lambda d: d.find_element(By.XPATH, "//*[text()='10000']")
)
assert dash_dcc.get_logs() == []