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.
* 🐛 fix #594 * 🐛 this fixes #593 * 💄 fix lint * ⚗️ add wait for clickable * :add percy reset * 🔧 add percy reset * rename job * 🔧 try on_fail step * 👌 add more check so less superfluous * 🔍
- Loading branch information
Showing
4 changed files
with
128 additions
and
56 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
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
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,110 @@ | ||
import itertools | ||
import pytest | ||
|
||
import dash_core_components as dcc | ||
import dash_html_components as html | ||
import dash | ||
from dash.dependencies import Input, Output | ||
import dash.testing.wait as wait | ||
|
||
DAY_SELECTOR = 'div[data-visible="true"] td.CalendarDay' | ||
|
||
|
||
@pytest.mark.DCC594 | ||
def test_cdpr001_date_clearable_true_works(dash_duo): | ||
|
||
app = dash.Dash(__name__) | ||
app.layout = html.Div([dcc.DatePickerRange(id="dpr", clearable=True)]) | ||
|
||
dash_duo.start_server(app) | ||
|
||
start_date = dash_duo.find_element('input[aria-label="Start Date"]') | ||
end_date = dash_duo.find_element('input[aria-label="End Date"]') | ||
|
||
start_date.click() | ||
|
||
dash_duo.find_elements(DAY_SELECTOR)[0].click() | ||
dash_duo.find_elements(DAY_SELECTOR)[-1].click() | ||
|
||
close_btn = dash_duo.wait_for_element('button[aria-label="Clear Dates"]') | ||
|
||
assert start_date.get_attribute("value") and end_date.get_attribute( | ||
"value" | ||
), "both start date and end date should get values" | ||
|
||
close_btn.click() | ||
assert not start_date.get_attribute( | ||
"value" | ||
) and not end_date.get_attribute( | ||
"value" | ||
), "both start and end dates should be cleared" | ||
|
||
|
||
def test_cdpr002_updatemodes(dash_duo): | ||
app = dash.Dash(__name__) | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.DatePickerRange( | ||
id="date-picker-range", | ||
start_date_id="startDate", | ||
end_date_id="endDate", | ||
start_date_placeholder_text="Select a start date!", | ||
end_date_placeholder_text="Select an end date!", | ||
updatemode="bothdates", | ||
), | ||
html.Div(id="date-picker-range-output"), | ||
] | ||
) | ||
|
||
@app.callback( | ||
Output("date-picker-range-output", "children"), | ||
[ | ||
Input("date-picker-range", "start_date"), | ||
Input("date-picker-range", "end_date"), | ||
], | ||
) | ||
def update_output(start_date, end_date): | ||
return "{} - {}".format(start_date, end_date) | ||
|
||
dash_duo.start_server(app=app) | ||
|
||
start_date = dash_duo.find_element("#startDate") | ||
start_date.click() | ||
|
||
end_date = dash_duo.find_element("#endDate") | ||
end_date.click() | ||
|
||
assert ( | ||
dash_duo.find_element("#date-picker-range-output").text | ||
== "None - None" | ||
), "the output should not update when both clicked but no selection happen" | ||
|
||
start_date.click() | ||
|
||
dash_duo.find_elements(DAY_SELECTOR)[4].click() | ||
assert ( | ||
dash_duo.find_element("#date-picker-range-output").text | ||
== "None - None" | ||
), "the output should not update when only one is selected" | ||
|
||
eday = dash_duo.find_elements(DAY_SELECTOR)[-4] | ||
wait.until(lambda: eday.is_displayed() and eday.is_enabled(), timeout=2) | ||
eday.click() | ||
|
||
date_tokens = set(start_date.get_attribute("value").split("/")) | ||
date_tokens.update(end_date.get_attribute("value").split("/")) | ||
|
||
assert ( | ||
set( | ||
itertools.chain( | ||
*[ | ||
_.split("-") | ||
for _ in dash_duo.find_element( | ||
"#date-picker-range-output" | ||
).text.split(" - ") | ||
] | ||
) | ||
) | ||
== date_tokens | ||
), "date should match the callback output" |
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