This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
byron
committed
Jul 15, 2019
1 parent
e4b0999
commit 49d979a
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
from selenium.common.exceptions import WebDriverException | ||
import dash | ||
from dash.dependencies import Input, Output | ||
import dash_core_components as dcc | ||
import dash_html_components as html | ||
|
||
ALLOWING_TYPES = ( | ||
"text", | ||
"number", | ||
"password", | ||
"email", | ||
"range", | ||
"search", | ||
"tel", | ||
"url", | ||
"hidden", | ||
) | ||
|
||
|
||
def test_intp001_all_types(dash_duo): | ||
def input_id(type_): | ||
return "input_{}".format(type_) | ||
|
||
app = dash.Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
dcc.Input( | ||
id=input_id(_), type=_, placeholder="input type {}".format(_) | ||
) | ||
for _ in ALLOWING_TYPES | ||
] | ||
+ [html.Div(id="output")] | ||
) | ||
|
||
@app.callback( | ||
Output("output", "children"), | ||
[Input(input_id(_), "value") for _ in ALLOWING_TYPES], | ||
) | ||
def cb_render(*vals): | ||
return " | ".join((val for val in vals if val)) | ||
|
||
dash_duo.start_server(app) | ||
|
||
assert ( | ||
dash_duo.find_element("#input_hidden").get_attribute("type") | ||
== "hidden" | ||
), "hidden input element should present with hidden type" | ||
|
||
dash_duo.percy_snapshot("intp001 - init state") | ||
|
||
for atype in ALLOWING_TYPES[:-1]: | ||
dash_duo.find_element("#input_{}".format(atype)).send_keys( | ||
"test intp001 - input[{}]".format(atype) | ||
) | ||
|
||
with pytest.raises(WebDriverException): | ||
dash_duo.find_element("#input_hidden").send_keys("no interaction") | ||
|
||
dash_duo.percy_snapshot("intp001 - callback output rendering") | ||
|
||
|
||
def test_intp100_number_type(dash_duo): | ||
app = dash.Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
dcc.Input( | ||
id="num", | ||
type="number", | ||
placeholder="this input is number type", | ||
) | ||
] | ||
) | ||
|
||
dash_duo.start_server(app) | ||
|
||
num_input = dash_duo.find_element('#num') | ||
assert not num_input.get_attribute('value') | ||
|
||
|