diff --git a/src/utils/convertToMoment.js b/src/utils/convertToMoment.js index e64ab7088..5b7927b1d 100644 --- a/src/utils/convertToMoment.js +++ b/src/utils/convertToMoment.js @@ -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); diff --git a/tests/integration/calendar/test_date_picker_range.py b/tests/integration/calendar/test_date_picker_range.py new file mode 100644 index 000000000..9ec4a80a0 --- /dev/null +++ b/tests/integration/calendar/test_date_picker_range.py @@ -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' + ) diff --git a/tests/integration/calendar/test_date_picker_single.py b/tests/integration/calendar/test_date_picker_single.py index 5b6bdc752..c17bf111f 100644 --- a/tests/integration/calendar/test_date_picker_single.py +++ b/tests/integration/calendar/test_date_picker_single.py @@ -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' + )