Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 695155a

Browse files
byronbyronz
authored andcommitted
migrate the long test_gallery test
1 parent fface5b commit 695155a

File tree

3 files changed

+304
-314
lines changed

3 files changed

+304
-314
lines changed

tests/integration/misc/conftest.py

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
from datetime import datetime
2+
import pytest
3+
import dash
4+
import dash_core_components as dcc
5+
import dash_html_components as html
6+
7+
8+
OPTIONS = [
9+
{"label": "New York City", "value": "NYC"},
10+
{"label": u"Montréal", "value": "MTL"},
11+
{"label": "San Francisco", "value": "SF"},
12+
{"label": u"北京", "value": u"帝都"},
13+
{"label": u"臺北", "value": u"天龍國"},
14+
]
15+
16+
17+
@pytest.fixture(scope="module")
18+
def platter_app():
19+
app = dash.Dash(__name__)
20+
21+
app.layout = html.Div(
22+
[
23+
html.Div(id="waitfor"),
24+
html.Label("Upload"),
25+
dcc.Upload(),
26+
html.Label("Horizontal Tabs"),
27+
dcc.Tabs(
28+
id="tabs",
29+
children=[
30+
dcc.Tab(
31+
label="Tab one",
32+
className="test",
33+
style={"border": "1px solid magenta"},
34+
children=[html.Div(["Test"])],
35+
),
36+
dcc.Tab(
37+
label="Tab two",
38+
children=[
39+
html.Div(
40+
[
41+
html.H1("This is the content in tab 2"),
42+
html.P("A graph here would be nice!"),
43+
]
44+
)
45+
],
46+
id="tab-one",
47+
),
48+
dcc.Tab(
49+
label="Tab three",
50+
children=[
51+
html.Div([html.H1("This is the content in tab 3")])
52+
],
53+
),
54+
],
55+
style={"fontFamily": "system-ui"},
56+
content_style={"border": "1px solid #d6d6d6", "padding": "44px"},
57+
parent_style={"maxWidth": "1000px", "margin": "0 auto"},
58+
),
59+
html.Label("Vertical Tabs"),
60+
dcc.Tabs(
61+
id="tabs1",
62+
vertical=True,
63+
children=[
64+
dcc.Tab(label="Tab one", children=[html.Div(["Test"])]),
65+
dcc.Tab(
66+
label="Tab two",
67+
children=[
68+
html.Div(
69+
[
70+
html.H1("This is the content in tab 2"),
71+
html.P("A graph here would be nice!"),
72+
]
73+
)
74+
],
75+
),
76+
dcc.Tab(
77+
label="Tab three",
78+
children=[
79+
html.Div([html.H1("This is the content in tab 3")])
80+
],
81+
),
82+
],
83+
),
84+
html.Label("Dropdown"),
85+
dcc.Dropdown(options=OPTIONS, value="MTL", id="dropdown"),
86+
html.Label("Multi-Select Dropdown"),
87+
dcc.Dropdown(options=OPTIONS, value=["MTL", "SF"], multi=True),
88+
html.Label("Radio Items"),
89+
dcc.RadioItems(options=OPTIONS, value="MTL"),
90+
html.Label("Checkboxes"),
91+
dcc.Checklist(options=OPTIONS, value=["MTL", "SF"]),
92+
html.Label("Text Input"),
93+
dcc.Input(value="", placeholder="type here", id="textinput"),
94+
html.Label("Disabled Text Input"),
95+
dcc.Input(
96+
value="disabled",
97+
type="text",
98+
id="disabled-textinput",
99+
disabled=True,
100+
),
101+
html.Label("Slider"),
102+
dcc.Slider(
103+
min=0,
104+
max=9,
105+
marks={
106+
i: "Label {}".format(i) if i == 1 else str(i)
107+
for i in range(1, 6)
108+
},
109+
value=5,
110+
),
111+
html.Label("Graph"),
112+
dcc.Graph(
113+
id="graph",
114+
figure={
115+
"data": [{"x": [1, 2, 3], "y": [4, 1, 4]}],
116+
"layout": {"title": u"北京"},
117+
},
118+
),
119+
html.Div(
120+
[
121+
html.Label("DatePickerSingle"),
122+
dcc.DatePickerSingle(
123+
id="date-picker-single", date=datetime(1997, 5, 10)
124+
),
125+
html.Div(
126+
[
127+
html.Label("DatePickerSingle - empty input"),
128+
dcc.DatePickerSingle(),
129+
],
130+
id="dt-single-no-date-value",
131+
),
132+
html.Div(
133+
[
134+
html.Label(
135+
"DatePickerSingle - initial visible month (May 97)"
136+
),
137+
dcc.DatePickerSingle(
138+
initial_visible_month=datetime(1997, 5, 10)
139+
),
140+
],
141+
id="dt-single-no-date-value-init-month",
142+
),
143+
]
144+
),
145+
html.Div(
146+
[
147+
html.Label("DatePickerRange"),
148+
dcc.DatePickerRange(
149+
id="date-picker-range",
150+
start_date_id="startDate",
151+
end_date_id="endDate",
152+
start_date=datetime(1997, 5, 3),
153+
end_date_placeholder_text="Select a date!",
154+
),
155+
html.Div(
156+
[
157+
html.Label("DatePickerRange - empty input"),
158+
dcc.DatePickerRange(
159+
start_date_id="startDate",
160+
end_date_id="endDate",
161+
start_date_placeholder_text="Start date",
162+
end_date_placeholder_text="End date",
163+
),
164+
],
165+
id="dt-range-no-date-values",
166+
),
167+
html.Div(
168+
[
169+
html.Label(
170+
"DatePickerRange - initial visible month (May 97)"
171+
),
172+
dcc.DatePickerRange(
173+
start_date_id="startDate",
174+
end_date_id="endDate",
175+
start_date_placeholder_text="Start date",
176+
end_date_placeholder_text="End date",
177+
initial_visible_month=datetime(1997, 5, 10),
178+
),
179+
],
180+
id="dt-range-no-date-values-init-month",
181+
),
182+
]
183+
),
184+
html.Label("TextArea"),
185+
dcc.Textarea(
186+
placeholder="Enter a value... 北京", style={"width": "100%"}
187+
),
188+
html.Label("Markdown"),
189+
dcc.Markdown(
190+
"""
191+
#### Dash and Markdown
192+
193+
Dash supports [Markdown](https://rexxars.github.io/react-markdown/).
194+
195+
Markdown is a simple way to write and format text.
196+
It includes a syntax for things like **bold text** and *italics*,
197+
[links](https://rexxars.github.io/react-markdown/), inline `code` snippets, lists,
198+
quotes, and more.
199+
200+
1. Links are auto-rendered: https://dash.plot.ly.
201+
2. This uses ~commonmark~ GitHub flavored markdown.
202+
203+
Tables are also supported:
204+
205+
| First Header | Second Header |
206+
| ------------- | ------------- |
207+
| Content Cell | Content Cell |
208+
| Content Cell | Content Cell |
209+
210+
北京
211+
""".replace(
212+
" ", ""
213+
)
214+
),
215+
dcc.Markdown(["# Line one", "## Line two"]),
216+
dcc.Markdown(),
217+
dcc.Markdown(
218+
"""
219+
```py
220+
import python
221+
print(3)
222+
```"""
223+
),
224+
dcc.Markdown(["```py", "import python", "print(3)", "```"]),
225+
dcc.Markdown(),
226+
]
227+
)
228+
229+
yield app
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import pytest
2+
3+
from selenium.webdriver.common.keys import Keys
4+
from selenium.common.exceptions import WebDriverException
5+
6+
7+
def test_mspl001_dcc_components_platter(platter_app, dash_duo):
8+
9+
dash_duo.start_server(platter_app)
10+
11+
dash_duo.wait_for_element("#waitfor")
12+
dash_duo.percy_snapshot("gallery")
13+
14+
dash_duo.find_element("#dropdown .Select-input input").send_keys(u"北")
15+
dash_duo.percy_snapshot("gallery - chinese character")
16+
17+
text_input = dash_duo.find_element("#textinput")
18+
assert (
19+
text_input.get_attribute("type") == "text"
20+
), "the default input type should be text"
21+
22+
text_input.send_keys("HODOR")
23+
24+
with pytest.raises(WebDriverException):
25+
dash_duo.find_element("#disabled-textinput").send_keys("RODOH")
26+
27+
dash_duo.percy_snapshot("gallery - text input")
28+
29+
# DatePickerSingle and DatePickerRange test
30+
# for issue with datepicker when date value is `None`
31+
32+
def reset_input(elem):
33+
elem.send_keys(len(elem.get_attribute("value"))* Keys.BACKSPACE)
34+
elem.send_keys("1997-05-03")
35+
36+
dt_input_1 = dash_duo.find_element("#dt-single-no-date-value #date")
37+
dt_input_1.click()
38+
dash_duo.percy_snapshot(
39+
"gallery - DatePickerSingle's datepicker "
40+
"when no date value and no initial month specified"
41+
)
42+
reset_input(dt_input_1)
43+
44+
dt_input_2 = dash_duo.find_element(
45+
"#dt-single-no-date-value-init-month #date"
46+
)
47+
dash_duo.find_element("label").click()
48+
dt_input_2.click()
49+
dash_duo.percy_snapshot(
50+
"gallery - DatePickerSingle's datepicker "
51+
"when no date value, but initial month is specified"
52+
)
53+
reset_input(dt_input_2)
54+
55+
dt_input_3 = dash_duo.find_element("#dt-range-no-date-values #endDate")
56+
dash_duo.find_element("label").click()
57+
dt_input_3.click()
58+
dash_duo.percy_snapshot(
59+
"gallery - DatePickerRange's datepicker "
60+
"when neither start date nor end date "
61+
"nor initial month is specified"
62+
)
63+
reset_input(dt_input_3)
64+
65+
dt_input_4 = dash_duo.find_element(
66+
"#dt-range-no-date-values-init-month #endDate"
67+
)
68+
dash_duo.find_element("label").click()
69+
dt_input_4.click()
70+
dash_duo.percy_snapshot(
71+
"gallery - DatePickerRange's datepicker "
72+
"when neither start date nor end date is specified, "
73+
"but initial month is"
74+
)
75+
reset_input(dt_input_4)

0 commit comments

Comments
 (0)