Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
✅ PR preview is ready!
|
frontend/lib/src/components/widgets/DateInput/DateInput.test.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Bob Nisco <[email protected]>
|
|
||
|
|
||
| def test_quick_select_feature_visibility(app: Page): | ||
| """Test that quick select is visible for range inputs and hidden for single inputs.""" | ||
| # Test range input (index 2 is "Range, no date") | ||
| range_date_input = app.get_by_test_id("stDateInput").nth(2) | ||
| range_date_input.click() | ||
|
|
||
| # Quick select should be visible for range inputs | ||
| quick_select = app.locator('[data-baseweb="select"]') | ||
| expect(quick_select).to_be_visible() | ||
|
|
||
| # Close the calendar | ||
| app.keyboard.press("Escape") | ||
|
|
||
| # Test single date input (index 0 is "Single date") | ||
| single_date_input = app.get_by_test_id("stDateInput").first | ||
| single_date_input.click() | ||
|
|
||
| # Quick select should not be visible for single date inputs | ||
| expect(quick_select).not_to_be_visible() |
There was a problem hiding this comment.
The test function is missing a return type annotation. Adding -> None would align with the project's typing standards for test functions and improve code clarity:
def test_quick_select_feature_visibility(app: Page) -> None:This maintains consistency with the typing conventions used throughout the test suite.
| def test_quick_select_feature_visibility(app: Page): | |
| """Test that quick select is visible for range inputs and hidden for single inputs.""" | |
| # Test range input (index 2 is "Range, no date") | |
| range_date_input = app.get_by_test_id("stDateInput").nth(2) | |
| range_date_input.click() | |
| # Quick select should be visible for range inputs | |
| quick_select = app.locator('[data-baseweb="select"]') | |
| expect(quick_select).to_be_visible() | |
| # Close the calendar | |
| app.keyboard.press("Escape") | |
| # Test single date input (index 0 is "Single date") | |
| single_date_input = app.get_by_test_id("stDateInput").first | |
| single_date_input.click() | |
| # Quick select should not be visible for single date inputs | |
| expect(quick_select).not_to_be_visible() | |
| def test_quick_select_feature_visibility(app: Page) -> None: | |
| """Test that quick select is visible for range inputs and hidden for single inputs.""" | |
| # Test range input (index 2 is "Range, no date") | |
| range_date_input = app.get_by_test_id("stDateInput").nth(2) | |
| range_date_input.click() | |
| # Quick select should be visible for range inputs | |
| quick_select = app.locator('[data-baseweb="select"]') | |
| expect(quick_select).to_be_visible() | |
| # Close the calendar | |
| app.keyboard.press("Escape") | |
| # Test single date input (index 0 is "Single date") | |
| single_date_input = app.get_by_test_id("stDateInput").first | |
| single_date_input.click() | |
| # Quick select should not be visible for single date inputs | |
| expect(quick_select).not_to_be_visible() | |
Spotted by Diamond (based on custom rules)
Is this helpful? React 👍 or 👎 to let us know.
| quick_select = app.locator('[data-baseweb="select"]') | ||
| expect(quick_select).to_be_visible() | ||
|
|
||
| # Close the calendar | ||
| app.keyboard.press("Escape") | ||
|
|
||
| # Test single date input (index 0 is "Single date") | ||
| single_date_input = app.get_by_test_id("stDateInput").first | ||
| single_date_input.click() | ||
|
|
||
| # Quick select should not be visible for single date inputs | ||
| expect(quick_select).not_to_be_visible() |
There was a problem hiding this comment.
The test reuses the same quick_select locator for both test cases, which could lead to flaky results. When testing the single date input, the locator should be re-queried after opening that calendar to ensure it's testing the current DOM state rather than potentially referencing elements from the previous interaction. Consider creating a new locator after clicking on the single date input to make the test more reliable.
| quick_select = app.locator('[data-baseweb="select"]') | |
| expect(quick_select).to_be_visible() | |
| # Close the calendar | |
| app.keyboard.press("Escape") | |
| # Test single date input (index 0 is "Single date") | |
| single_date_input = app.get_by_test_id("stDateInput").first | |
| single_date_input.click() | |
| # Quick select should not be visible for single date inputs | |
| expect(quick_select).not_to_be_visible() | |
| quick_select = app.locator('[data-baseweb="select"]') | |
| expect(quick_select).to_be_visible() | |
| # Close the calendar | |
| app.keyboard.press("Escape") | |
| # Test single date input (index 0 is "Single date") | |
| single_date_input = app.get_by_test_id("stDateInput").first | |
| single_date_input.click() | |
| # Re-query the quick select locator to ensure we're testing the current DOM state | |
| quick_select_for_single_date = app.locator('[data-baseweb="select"]') | |
| # Quick select should not be visible for single date inputs | |
| expect(quick_select_for_single_date).not_to_be_visible() |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
#12295) ## Describe your changes - Problem: BaseWeb’s quick select returns midday-anchored Date objects (12:00), while our min/max bounds are midnight. Our validation compared full datetimes, so same-day end dates were flagged as > max. - Changes: - Normalize all selected dates to `00:00` in `handleChange` before validation and state updates. - Normalize stored values in `updateWidgetMgrState` before validation. - Tests: - Add unit test asserting a quick-select range ending "today" is accepted with `max` set to today and no error icon is shown. - Stabilize time by mocking `moment.now` and `Date`, avoiding fake timers that interfere with BaseWeb popovers. ## GitHub Issue Link (if applicable) Fixes #12293 Ref #10166, #10764 ## Testing Plan - ✅ Unit Tests (JS and/or Python) --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Describe your changes
Adds BaseWeb's quick select dropdown to

st.date_inputwhen it's set up to select a date range:GitHub Issue Link (if applicable)
#11108
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.