Skip to content

Conversation

@codomposer
Copy link
Contributor


name: Pull Request
about: Create a pull request to improve this repository
title: "test: add unit tests with documentation for 8 previously untested components"
labels: "testing"
assignees: ""

Description

Linked issue: N/A

Problem
Several core components in the react-datepicker library lacked dedicated unit tests, making it difficult to:

  • Verify component behavior and prevent regressions
  • Understand component functionality through test documentation
  • Maintain code quality and confidence during refactoring
  • Ensure accessibility features work correctly

The following components had no test coverage:

  • CalendarContainer - Accessibility wrapper
  • ClickOutsideWrapper - Click detection utility
  • Portal - DOM portal rendering
  • TabLoop - Keyboard navigation management
  • withFloating - Higher-Order Component for Floating UI
  • PopperComponent - Component orchestration
  • MonthDropdownOptions - Month selection dropdown
  • Year - Year picker component

Changes
Added comprehensive unit tests for 8 previously untested components:

  1. calendar_container_test.test.tsx (78 lines)

    • Tests ARIA attributes and accessibility features
    • Verifies time selection modes
    • Tests custom className and HTML attribute passthrough
  2. click_outside_wrapper_test.test.tsx (252 lines)

    • Tests click detection (inside vs outside)
    • Tests ignore class functionality
    • Tests event listener cleanup and memory leak prevention
    • Tests Shadow DOM support with composed events
    • Tests ref forwarding and dynamic handler updates
  3. portal_test.test.tsx (218 lines)

    • Tests portal creation and rendering
    • Tests automatic portal root creation and reuse
    • Tests Shadow DOM support
    • Tests cleanup on unmount
    • Tests multiple independent portals
  4. tab_loop_test.test.tsx (297 lines)

    • Tests tab loop creation with start/end sentinels
    • Tests focus management (first/last element cycling)
    • Tests disabled element handling
    • Tests various focusable element types
    • Tests enable/disable functionality
  5. with_floating_test.test.tsx (226 lines)

    • Tests HOC wrapping and prop passthrough
    • Tests Floating UI integration
    • Tests display name generation
    • Tests middleware, placement, and autoUpdate
  6. popper_component_test.test.tsx (324 lines)

    • Tests target and popper rendering
    • Tests portal and TabLoop integration
    • Tests arrow rendering
    • Tests keyboard event handling
    • Tests Shadow DOM support
  7. month_dropdown_options_test.test.tsx (373 lines)

    • Tests month option rendering and selection
    • Tests keyboard navigation (Enter, Escape, Arrow keys)
    • Tests wrap-around behavior
    • Tests ARIA attributes and accessibility
  8. year_test.test.tsx (557 lines)

    • Tests year range rendering
    • Tests keyboard navigation
    • Tests range selection visualization
    • Tests disabled years (minDate, maxDate, filters)
    • Tests ARIA attributes and accessibility

Documentation improvements:

  • Added comprehensive JSDoc comments to test suites explaining component purpose
  • Added test-level comments describing what each test verifies
  • Added inline comments for complex logic

Screenshots

N/A - This PR adds test coverage only

To reviewers

  • All tests follow the existing project patterns using @testing-library/react and Jest
  • Tests include comprehensive coverage of rendering, user interactions, keyboard navigation, and accessibility
  • Mock implementations are used for external dependencies (Floating UI, Portal, TabLoop) to isolate component logic
  • TypeScript lint errors in IDE are expected (missing type definitions) but do not affect test execution
  • All tests pass successfully with yarn test

Test execution:

yarn test  # Run all tests
yarn test:ci  # Run with coverage

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

…ponents (CalendarContainer, ClickOutsideWrapper, Portal, TabLoop, withFloating, PopperComponent, MonthDropdownOptions, Year)
@codomposer codomposer changed the title add unit tests with documentation for 8 previously untested ponents add unit tests with documentation for 8 previously untested components Nov 4, 2025
@codomposer codomposer closed this Nov 4, 2025
@codomposer codomposer reopened this Nov 10, 2025
@codomposer codomposer closed this Nov 10, 2025
@codomposer codomposer deleted the fix/test-script branch November 11, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant