|
6 | 6 | ElementClickInterceptedException, |
7 | 7 | TimeoutException, |
8 | 8 | ) |
| 9 | +from selenium.webdriver.common.by import By |
9 | 10 | from selenium.webdriver.common.keys import Keys |
10 | 11 |
|
11 | 12 |
|
@@ -377,6 +378,97 @@ def test_dtpr008_input_click_opens_but_keeps_focus(dash_dcc): |
377 | 378 | assert dash_dcc.get_logs() == [] |
378 | 379 |
|
379 | 380 |
|
| 381 | +def test_dtpr009_same_date_selection_minimum_nights_zero(dash_dcc): |
| 382 | + """Bug #3645: With minimum_nights=0, selecting the same date for start and end should work.""" |
| 383 | + app = Dash(__name__) |
| 384 | + app.layout = html.Div( |
| 385 | + [ |
| 386 | + dcc.DatePickerRange( |
| 387 | + id="dpr", |
| 388 | + min_date_allowed=datetime(2021, 1, 1), |
| 389 | + max_date_allowed=datetime(2021, 1, 31), |
| 390 | + initial_visible_month=datetime(2021, 1, 1), |
| 391 | + minimum_nights=0, |
| 392 | + display_format="MM/DD/YYYY", |
| 393 | + ), |
| 394 | + html.Div(id="output"), |
| 395 | + ] |
| 396 | + ) |
| 397 | + |
| 398 | + @app.callback( |
| 399 | + Output("output", "children"), |
| 400 | + Input("dpr", "start_date"), |
| 401 | + Input("dpr", "end_date"), |
| 402 | + ) |
| 403 | + def display_dates(start_date, end_date): |
| 404 | + return f"Start: {start_date}, End: {end_date}" |
| 405 | + |
| 406 | + dash_dcc.start_server(app) |
| 407 | + |
| 408 | + # Select day 10 for both start and end (same date) |
| 409 | + result = dash_dcc.select_date_range("dpr", day_range=(10, 10)) |
| 410 | + assert result == ( |
| 411 | + "01/10/2021", |
| 412 | + "01/10/2021", |
| 413 | + ), f"Same date selection should work with minimum_nights=0, got {result}" |
| 414 | + |
| 415 | + dash_dcc.wait_for_text_to_equal("#output", "Start: 2021-01-10, End: 2021-01-10") |
| 416 | + |
| 417 | + assert dash_dcc.get_logs() == [] |
| 418 | + |
| 419 | + |
| 420 | +def test_dtpr010_new_start_date_clears_end_date(dash_dcc): |
| 421 | + """Bug #3645: When a new start date is selected after a range, end_date should be cleared.""" |
| 422 | + app = Dash(__name__) |
| 423 | + app.layout = html.Div( |
| 424 | + [ |
| 425 | + dcc.DatePickerRange( |
| 426 | + id="dpr", |
| 427 | + min_date_allowed=datetime(2021, 1, 1), |
| 428 | + max_date_allowed=datetime(2021, 1, 31), |
| 429 | + initial_visible_month=datetime(2021, 1, 1), |
| 430 | + minimum_nights=0, |
| 431 | + display_format="MM/DD/YYYY", |
| 432 | + ), |
| 433 | + html.Div(id="output"), |
| 434 | + ] |
| 435 | + ) |
| 436 | + |
| 437 | + @app.callback( |
| 438 | + Output("output", "children"), |
| 439 | + Input("dpr", "start_date"), |
| 440 | + Input("dpr", "end_date"), |
| 441 | + ) |
| 442 | + def display_dates(start_date, end_date): |
| 443 | + return f"Start: {start_date}, End: {end_date}" |
| 444 | + |
| 445 | + dash_dcc.start_server(app) |
| 446 | + |
| 447 | + # First, select a range: Jan 2 to Jan 11 |
| 448 | + dash_dcc.select_date_range("dpr", day_range=(2, 11)) |
| 449 | + dash_dcc.wait_for_text_to_equal("#output", "Start: 2021-01-02, End: 2021-01-11") |
| 450 | + |
| 451 | + # Now click just a new start date (Jan 4) without selecting an end date |
| 452 | + date = dash_dcc.find_element("#dpr") |
| 453 | + date.click() |
| 454 | + dash_dcc._wait_until_day_is_clickable() |
| 455 | + days = dash_dcc.find_elements(dash_dcc.date_picker_day_locator) |
| 456 | + day_4 = [d for d in days if d.find_element(By.CSS_SELECTOR, "span").text == "4"][0] |
| 457 | + day_4.click() |
| 458 | + |
| 459 | + # The calendar should still be open (waiting for end date). |
| 460 | + # The old end_date (Jan 11) should NOT be retained. |
| 461 | + # Click outside to close the calendar. |
| 462 | + time.sleep(0.3) |
| 463 | + dash_dcc.find_element("body").click() |
| 464 | + time.sleep(0.3) |
| 465 | + |
| 466 | + # end_date must be cleared, not silently retained from previous selection |
| 467 | + dash_dcc.wait_for_text_to_equal("#output", "Start: 2021-01-04, End: None") |
| 468 | + |
| 469 | + assert dash_dcc.get_logs() == [] |
| 470 | + |
| 471 | + |
380 | 472 | def test_dtpr030_external_date_range_update(dash_dcc): |
381 | 473 | """Test that DatePickerRange accepts external date updates via callback without resetting.""" |
382 | 474 | app = Dash(__name__) |
|
0 commit comments