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

Commit

Permalink
Use start date, if one is supplied, for initial_visible_month. (#687)
Browse files Browse the repository at this point in the history
* Use start_date or min_date_allowed for initial_visible_month if initial_visible_month is undefined.

* Add test for initial month.

* Add datePickerRange tests.

* Use max date allowed

* Make function call simpler.

* Run linter.

* Fix typo.
  • Loading branch information
Shammamah Hossain authored Nov 6, 2019
1 parent 0e14498 commit e371b34
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/convertToMoment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export default (newProps, momentProps) => {
dest[key] = null;

if (key === 'initial_visible_month') {
dest[key] = moment();
dest[key] = moment(
newProps.start_date ||
newProps.min_date_allowed ||
newProps.end_date ||
newProps.max_date_allowed ||
undefined
);
}
} else {
dest[key] = moment(value);
Expand Down
76 changes: 76 additions & 0 deletions tests/integration/calendar/test_date_picker_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from datetime import datetime

import dash
import dash_html_components as html
import dash_core_components as dcc


def test_dtpr001_initial_month_provided(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.DatePickerRange(
id="dps-initial-month",
min_date_allowed=datetime(2010, 1, 1),
max_date_allowed=datetime(2099, 12, 31),
initial_visible_month=datetime(2019, 10, 28)
)
])

dash_dcc.start_server(app)

date_picker_start = dash_dcc.find_element(
'#dps-initial-month .DateInput_input.DateInput_input_1[placeholder="Start Date"]'
)
date_picker_start.click()

dash_dcc.wait_for_text_to_equal(
'#dps-initial-month .CalendarMonth.CalendarMonth_1[data-visible=true] strong',
'October 2019',
1
)


def test_dtpr002_no_initial_month_min_date(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.DatePickerRange(
id="dps-initial-month",
min_date_allowed=datetime(2010, 1, 1),
max_date_allowed=datetime(2099, 12, 31)
)
])

dash_dcc.start_server(app)

date_picker_start = dash_dcc.find_element(
'#dps-initial-month .DateInput_input.DateInput_input_1[placeholder="Start Date"]'
)
date_picker_start.click()

dash_dcc.wait_for_text_to_equal(
'#dps-initial-month .CalendarMonth.CalendarMonth_1[data-visible=true] strong',
'January 2010'
)


def test_dtpr003_no_initial_month_no_min_date_start_date(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.DatePickerRange(
id="dps-initial-month",
start_date=datetime(2019, 8, 13),
max_date_allowed=datetime(2099, 12, 31)
)
])

dash_dcc.start_server(app)

date_picker_start = dash_dcc.find_element(
'#dps-initial-month .DateInput_input.DateInput_input_1[placeholder="Start Date"]'
)
date_picker_start.click()

dash_dcc.wait_for_text_to_equal(
'#dps-initial-month .CalendarMonth.CalendarMonth_1[data-visible=true] strong',
'August 2019'
)
20 changes: 20 additions & 0 deletions tests/integration/calendar/test_date_picker_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,23 @@ def cb(clicks):
)
switched = dash_dcc.find_element("#dps-none input").get_attribute("value")
assert switched != amnesiaed and switched == ""


def test_dtps012_initial_month(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.DatePickerSingle(
id="dps-initial-month",
min_date_allowed=datetime(2010, 1, 1),
max_date_allowed=datetime(2099, 12, 31)
)
])

dash_dcc.start_server(app)

date_picker = dash_dcc.find_element('#dps-initial-month')
date_picker.click()
dash_dcc.wait_for_text_to_equal(
'#dps-initial-month .CalendarMonth.CalendarMonth_1[data-visible=true] strong',
'January 2010'
)

0 comments on commit e371b34

Please sign in to comment.