Skip to content

Reduce Coordinate Sensitivity in Hit-Detection Tests #211

@joekotvas

Description

@joekotvas

Context

Interactive hit-detection tests (like Interaction.test.tsx) currently use hardcoded clientX and clientY coordinates to simulate user interaction.

The Problem

  • Coordinates are derived from global layout constants (e.g., lineHeight, baseY, TOP_OFFSET).
  • When these constants change (as MEASURE_HIT_AREA_TOP_OFFSET recently did from 50 to 56), the tests break even if the logic is correct.
  • This creates high maintenance overhead for layout-related refactors.

Proposed Improvement

  • Move toward a more robust hit-detection testing strategy.
  • Options:
    1. Calculate coordinates in the test based on the same constants used in production.
    2. Use relative offsets within the hit area (e.g., 'middle of the staff', 'top ledger line').
    3. Find specific visual elements (staff lines) and offset from them.

Related Files

  • src/__tests__/Interaction.test.tsx
  • src/components/Canvas/Measure.tsx
  • src/constants.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions