Skip to content

Fix PolarAngleAxis event types, add tests for remaining components#7000

Merged
ckifer merged 2 commits intomainfrom
more-event-types
Feb 13, 2026
Merged

Fix PolarAngleAxis event types, add tests for remaining components#7000
ckifer merged 2 commits intomainfrom
more-event-types

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Feb 12, 2026

Description

Followup to make sure all our component types are compatible with the new function we're adding in 3.8

Related Issue

#6645

Summary by CodeRabbit

  • New Features

    • Exported TickItem as part of the public API
    • Added PolarAngleAxisEvents type with comprehensive event handlers for axis tick interactions
    • Added touch event support: onTouchStart, onTouchMove, onTouchEnd for PolarAngleAxis
  • Tests

    • Added type-checking tests for event handler compatibility across multiple components
    • Enhanced PolarAngleAxis test coverage with event interaction scenarios

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

Walkthrough

The PR exports TickItem as a public type and refactors PolarAngleAxis event handlers to use TickItem and SVGTextElement for improved type safety. Test utilities (Customized wrapper) are removed from cartesian tests, and comprehensive type-checking tests are added across PolarAngleAxis, PolarRadiusAxis, and shape components to verify event handler compatibility.

Changes

Cohort / File(s) Summary
Type System & Exports
omnidoc/verifyExamples.spec.ts, src/index.ts
TickItem added to public API exports and verifyExamples array for documentation tracking.
PolarAngleAxis Refactoring
src/polar/PolarAngleAxis.tsx
Introduces PolarAngleAxisEvents type with mouse/touch event handlers accepting TickItem. Replaces InsideProps with InternalPolarAngleAxisProps, updates function signatures, and refines event payload typing from generic any to TickItem.
Cartesian Test Cleanup
test/cartesian/ReferenceArea.spec.tsx, test/cartesian/ReferenceLine/ReferenceLine.spec.tsx, test/cartesian/XAxis/XAxis.brush.spec.tsx
Removes Customized wrapper component usage and imports; replaces with direct component rendering in test trees.
PolarAngleAxis Event Tests
test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx
Adds comprehensive event-handling test suite verifying onClick, onMouse\, and onTouch\ handlers with TickItem and index arguments; updates import paths.
Type Coverage Tests (Polar)
test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx, test/polar/PolarRadiusAxis.typed.spec.tsx
New TypeScript type-checking tests validating getRelativeCoordinate type compatibility across all event handlers on polar axis components.
Type Coverage Tests (Shapes)
test/shape/*.typed.spec.tsx (Cross, Curve, Dot, Polygon, Rectangle, Sector, Symbols, Trapezoid)
New TypeScript type-checking tests for shape components verifying event handler compatibility with getRelativeCoordinate across mouse and touch events.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. It lacks required template sections such as motivation, testing details, types of changes, and checklist items specified in the repository template. Complete the PR description by filling in all required sections from the template: Motivation and Context, How Has This Been Tested, Types of changes, and the Checklist section.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: fixing PolarAngleAxis event types and adding comprehensive tests for multiple shape components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch more-event-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx`:
- Line 2956: Leftover debug() call in PolarAngleAxis.spec.tsx prints the DOM on
every test run; remove the debug() invocation (the standalone debug() statement)
from the test file (where PolarAngleAxis tests are defined) so tests no longer
log the DOM—simply delete the call and run the test suite to confirm no other
debug artifacts remain.
- Around line 2926-2999: The test "should fire event handlers when provided" is
missing vi.useFakeTimers(), so add vi.useFakeTimers() at the start of that it
block (before render) to ensure timers/raf are faked for the rendered
RadarChart/PolarAngleAxis interactions, and then restore timers with
vi.useRealTimers() at the end of the test (or in an afterEach) to avoid leaking
fake timers; locate the block by the it title "should fire event handlers when
provided" (and related symbols like userEventSetup, render, onClick,
PolarAngleAxis) and insert the calls accordingly.
🧹 Nitpick comments (2)
src/polar/PolarAngleAxis.tsx (1)

240-242: Add JSDoc comments for touch event handlers.

The mouse event handlers (lines 208–239) all have JSDoc descriptions, but the three touch event handlers lack them. Since JSDoc in source files feeds auto-generated API documentation, these should be documented consistently.

📝 Proposed fix
+  /**
+   * The customized event handler of touchstart on the ticks of this axis
+   */
   onTouchStart?: (data: TickItem, index: number, e: React.TouchEvent<SVGTextElement>) => void;
+  /**
+   * The customized event handler of touchmove on the ticks of this axis
+   */
   onTouchMove?: (data: TickItem, index: number, e: React.TouchEvent<SVGTextElement>) => void;
+  /**
+   * The customized event handler of touchend on the ticks of this axis
+   */
   onTouchEnd?: (data: TickItem, index: number, e: React.TouchEvent<SVGTextElement>) => void;

As per coding guidelines, "JSDoc comments and TypeScript definitions in source files must be kept up-to-date as they are used to autogenerate API documentation via 'npm run omnidoc'".

test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx (1)

2973-2997: Prefer expectLastCalledWith helper over expect(spy).toHaveBeenLastCalledWith(...).

Line 2969 correctly uses expectLastCalledWith, but lines 2973, 2975, 2979, 2981, 2985, 2989, 2993, 2997 fall back to expect(spy).toHaveBeenLastCalledWith(...). For consistency and better typing, use the helper throughout. As per coding guidelines: "Use the expectLastCalledWith helper function instead of expect(spy).toHaveBeenLastCalledWith(...) for better typing and autocompletion".

♻️ Example fix for a few lines (apply same pattern to all)
-      expect(onMouseEnter).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onMouseEnter, tickItem, 0, expect.any(Object));
-      expect(onMouseOver).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onMouseOver, tickItem, 0, expect.any(Object));
-      expect(onMouseLeave).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onMouseLeave, tickItem, 0, expect.any(Object));
-      expect(onMouseOut).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onMouseOut, tickItem, 0, expect.any(Object));
-      expect(onMouseMove).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onMouseMove, tickItem, 0, expect.any(Object));
-      expect(onTouchStart).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onTouchStart, tickItem, 0, expect.any(Object));
-      expect(onTouchMove).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onTouchMove, tickItem, 0, expect.any(Object));
-      expect(onTouchEnd).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
+      expectLastCalledWith(onTouchEnd, tickItem, 0, expect.any(Object));

Comment on lines +2926 to +2999
describe('events', () => {
it('should fire event handlers when provided', async () => {
const userEvent = userEventSetup();
const onClick: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onMouseEnter: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onMouseLeave: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onMouseOver: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onMouseOut: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onMouseMove: Mock<(tickItem: TickItem, index: number, e: React.MouseEvent) => void> = vi.fn();
const onTouchStart: Mock<(tickItem: TickItem, index: number, e: React.TouchEvent) => void> = vi.fn();
const onTouchMove: Mock<(tickItem: TickItem, index: number, e: React.TouchEvent) => void> = vi.fn();
const onTouchEnd: Mock<(tickItem: TickItem, index: number, e: React.TouchEvent) => void> = vi.fn();

const { container, debug } = render(
<RadarChart width={100} height={100} data={[{ x: 1, y: 1 }]}>
<PolarRadiusAxis dataKey="x" />
<PolarAngleAxis
dataKey="y"
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onMouseMove={onMouseMove}
onTouchStart={onTouchStart}
onTouchMove={onTouchMove}
onTouchEnd={onTouchEnd}
/>
</RadarChart>,
);
debug();
const axisLabel = container.querySelector('.recharts-polar-angle-axis-tick');
assertNotNull(axisLabel);

await userEvent.click(axisLabel);
expect(onClick).toHaveBeenCalledTimes(1);

const tickItem: TickItem = {
coordinate: 90,
index: 0,
offset: 360,
value: 1,
};
expectLastCalledWith(onClick, tickItem, 0, expect.any(Object));

await userEvent.hover(axisLabel);
expect(onMouseEnter).toHaveBeenCalledTimes(1);
expect(onMouseEnter).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
expect(onMouseOver).toHaveBeenCalledTimes(1);
expect(onMouseOver).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));

await userEvent.unhover(axisLabel);
expect(onMouseLeave).toHaveBeenCalledTimes(1);
expect(onMouseLeave).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
expect(onMouseOut).toHaveBeenCalledTimes(1);
expect(onMouseOut).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));

await userEvent.pointer({ target: axisLabel, keys: '[MouseMove]' });
expect(onMouseMove).toHaveBeenCalledTimes(1);
expect(onMouseMove).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));

fireEvent.touchStart(axisLabel);
expect(onTouchStart).toHaveBeenCalledTimes(1);
expect(onTouchStart).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));

fireEvent.touchMove(axisLabel);
expect(onTouchMove).toHaveBeenCalledTimes(1);
expect(onTouchMove).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));

fireEvent.touchEnd(axisLabel);
expect(onTouchEnd).toHaveBeenCalledTimes(1);
expect(onTouchEnd).toHaveBeenLastCalledWith(tickItem, 0, expect.any(Object));
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing vi.useFakeTimers() in this test.

Per coding guidelines, all tests should use vi.useFakeTimers() due to Redux autoBatchEnhancer dependency on timers and requestAnimationFrame. This test uses direct render (not createSelectorTestCase), so timers aren't automatically managed. As per coding guidelines: "Use vi.useFakeTimers() in all tests due to Redux autoBatchEnhancer dependency on timers and requestAnimationFrame".

🤖 Prompt for AI Agents
In `@test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx` around lines 2926 - 2999,
The test "should fire event handlers when provided" is missing
vi.useFakeTimers(), so add vi.useFakeTimers() at the start of that it block
(before render) to ensure timers/raf are faked for the rendered
RadarChart/PolarAngleAxis interactions, and then restore timers with
vi.useRealTimers() at the end of the test (or in an afterEach) to avoid leaking
fake timers; locate the block by the it title "should fire event handlers when
provided" (and related symbols like userEventSetup, render, onClick,
PolarAngleAxis) and insert the calls accordingly.

/>
</RadarChart>,
);
debug();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove debug() call — leftover debug artifact.

This will print the DOM tree to console on every test run.

🧹 Proposed fix
-      debug();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
debug();
🤖 Prompt for AI Agents
In `@test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx` at line 2956, Leftover
debug() call in PolarAngleAxis.spec.tsx prints the DOM on every test run; remove
the debug() invocation (the standalone debug() statement) from the test file
(where PolarAngleAxis tests are defined) so tests no longer log the DOM—simply
delete the call and run the test suite to confirm no other debug artifacts
remain.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.10%. Comparing base (f5d634c) to head (731c087).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7000   +/-   ##
=======================================
  Coverage   90.10%   90.10%           
=======================================
  Files         522      522           
  Lines       38848    38848           
  Branches     5347     5347           
=======================================
  Hits        35004    35004           
  Misses       3835     3835           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Bundle Report

Changes will increase total bundle size by 357 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.25MB 160 bytes (0.01%) ⬆️
recharts/bundle-es6 1.09MB 160 bytes (0.01%) ⬆️
recharts/bundle-umd 539.31kB 37 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
polar/PolarAngleAxis.js 160 bytes 12.81kB 1.27%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
polar/PolarAngleAxis.js 160 bytes 11.37kB 1.43%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 37 bytes 539.31kB 0.01%

@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@ckifer ckifer merged commit d705e66 into main Feb 13, 2026
46 of 47 checks passed
@PavelVanecek PavelVanecek deleted the more-event-types branch February 13, 2026 06:10
@coderabbitai coderabbitai bot mentioned this pull request Mar 2, 2026
7 tasks
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.

2 participants