Skip to content

test: enhance line animation tests for ComposedChart and responsive#7289

Merged
PavelVanecek merged 2 commits into
mainfrom
line-animation-test
May 1, 2026
Merged

test: enhance line animation tests for ComposedChart and responsive#7289
PavelVanecek merged 2 commits into
mainfrom
line-animation-test

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

This pull request adds comprehensive new test cases to the Line.animation.spec.tsx file to improve the coverage of line animation behaviors, particularly in complex and responsive chart scenarios. The new tests focus on verifying the correct animation of lines in composed charts with sparse data, in responsive layouts, and when chart layout changes dynamically during animation.

The most important changes include:

New animation tests for complex scenarios:

  • Added tests for line animation in ComposedChart with sparse best-fit line data, ensuring the line path remains present and animates correctly as stroke-dasharray grows during entrance animation.
  • Added tests to verify that sparse best-fit lines in responsive ComposedChart continue animating correctly after a late resize event.

Responsive and dynamic layout animation tests:

  • Introduced tests for responsive charts that receive their size after mount, confirming that line animations reveal progressively after a resize rather than staying hidden until the animation ends.
  • Added tests to ensure that when layout changes (such as adding a Legend or a YAxis with width="auto") occur mid-animation, the visible stroke length of the animated line is preserved and not reset.

Test utility and import improvements:

  • Updated imports to include additional chart components (ComposedChart, Scatter, XAxis) and improved mocking utilities for bounding client rects.

Summary by CodeRabbit

  • Tests
    • Added animation regression tests covering line entrance behavior across composed and sparse chart scenarios, responsive layouts with delayed size updates, and dynamic layout changes (e.g., legend or axis width adjustments) during animations to ensure stroke reveal progresses correctly and does not reset mid-animation.

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: feb63813-0eea-4d88-829c-5967caf46321

📥 Commits

Reviewing files that changed from the base of the PR and between 33783e5 and 862d359.

📒 Files selected for processing (1)
  • test/cartesian/Line.animation.spec.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/cartesian/Line.animation.spec.tsx

Walkthrough

Adds a new test suite that validates Line entrance-animation behavior across composed and responsive charts, ensuring SVG path d is rendered and stroke-dasharray progresses (and does not reset) when layout or composition changes occur after initial mount.

Changes

Cohort / File(s) Summary
Line Animation Tests
test/cartesian/Line.animation.spec.tsx
Adds ~201 lines of regression tests covering: ComposedChart sparse two-Line cases, responsive charts with ResizeObserver stubs and late dimension updates, and re-render scenarios where Legend or YAxis width="auto" are added during entrance animations; asserts path d non-empty and stroke-dasharray progresses without resetting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: enhancing line animation tests for ComposedChart and responsive scenarios.
Description check ✅ Passed The description covers motivation (improving test coverage for complex scenarios), what was tested (composed charts, responsive layouts, dynamic layout changes), and includes detailed sections on new test additions and improvements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch line-animation-test

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/cartesian/Line.animation.spec.tsx (2)

570-577: ⚡ Quick win

Re-query line nodes after advancing animation progress.

Line 570 stores .recharts-line-curve nodes before setAnimationProgress(0.5), then reuses them at Line 575-576. If re-render swaps path nodes, these references can go stale and make the test flaky.

Suggested fix
-      const lines = Array.from(container.querySelectorAll<SVGPathElement>('.recharts-line-curve'));
+      let lines = Array.from(container.querySelectorAll<SVGPathElement>('.recharts-line-curve'));
       expect(lines).toHaveLength(2);
       expect(lines[0]).toHaveAttribute('stroke-dasharray');

       await animationManager.setAnimationProgress(0.5);
+      lines = Array.from(container.querySelectorAll<SVGPathElement>('.recharts-line-curve'));
       expect(lines[0]).toHaveAttribute('stroke-dasharray', '50px 100px');
       expect(lines[1]).toHaveAttribute('stroke-dasharray', '50px 100px');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/cartesian/Line.animation.spec.tsx` around lines 570 - 577, The test
captures SVG path elements into the local variable lines before calling
animationManager.setAnimationProgress(0.5), which can yield stale DOM references
if the component re-renders; update the test in Line.animation.spec.tsx to
re-query container.querySelectorAll<SVGPathElement>('.recharts-line-curve')
after calling setAnimationProgress(0.5) (i.e., call the same query again into a
new or overwritten lines variable before asserting stroke-dasharray on lines[0]
and lines[1]) so assertions use fresh DOM nodes.

334-351: ⚡ Quick win

Add selector call-count assertions for the new selector-based test cases.

The new createSelectorTestCase scenarios don’t validate selector invocation counts, so unnecessary re-renders in these new flows could slip through.

As per coding guidelines, “Verify the number of selector calls using the spy object from createSelectorTestCase to spot unnecessary re-renders and improve performance.”

Also applies to: 500-505, 604-605

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/cartesian/Line.animation.spec.tsx` around lines 334 - 351, The new
selector-based tests created with createSelectorTestCase (e.g., the
renderTestCase defined around the Line animation tests) are missing assertions
that verify selector invocation counts; update each selector-based test case
(including the ones around lines cited: 334-351, 500-505, 604-605) to assert the
spy object returned by createSelectorTestCase was called the expected number of
times after each render/update to catch unnecessary re-renders—locate the spy
from the createSelectorTestCase helper and add assertions like spy.callCount (or
the helper’s exposed API) after initial render and after any prop/state changes
in the test flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/cartesian/Line.animation.spec.tsx`:
- Around line 606-614: The test currently only asserts the stroke-dasharray is
not "0px 0px" after rerender, which allows partial regressions; change the
assertion to capture the pre-rerender value and assert it is preserved exactly
after rerender. Concretely, in the test "should not reset the visible stroke
length when Legend is added mid-animation" use getLine(container) to read and
store the initial stroke-dasharray after await
animationManager.setAnimationProgress(0.5) (e.g., const initial =
getLine(container).getAttribute('stroke-dasharray')), then call
rerender(ChartWithLegend) and assert
getLine(container).getAttribute('stroke-dasharray') === initial; apply the same
change to the other similar test block noted (lines 616-624).

---

Nitpick comments:
In `@test/cartesian/Line.animation.spec.tsx`:
- Around line 570-577: The test captures SVG path elements into the local
variable lines before calling animationManager.setAnimationProgress(0.5), which
can yield stale DOM references if the component re-renders; update the test in
Line.animation.spec.tsx to re-query
container.querySelectorAll<SVGPathElement>('.recharts-line-curve') after calling
setAnimationProgress(0.5) (i.e., call the same query again into a new or
overwritten lines variable before asserting stroke-dasharray on lines[0] and
lines[1]) so assertions use fresh DOM nodes.
- Around line 334-351: The new selector-based tests created with
createSelectorTestCase (e.g., the renderTestCase defined around the Line
animation tests) are missing assertions that verify selector invocation counts;
update each selector-based test case (including the ones around lines cited:
334-351, 500-505, 604-605) to assert the spy object returned by
createSelectorTestCase was called the expected number of times after each
render/update to catch unnecessary re-renders—locate the spy from the
createSelectorTestCase helper and add assertions like spy.callCount (or the
helper’s exposed API) after initial render and after any prop/state changes in
the test flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f3d3c67-0db8-4c4a-91c6-2b586b0aeb33

📥 Commits

Reviewing files that changed from the base of the PR and between 16d5b0d and 33783e5.

📒 Files selected for processing (1)
  • test/cartesian/Line.animation.spec.tsx

Comment on lines +606 to +614
it('should not reset the visible stroke length when Legend is added mid-animation', async () => {
const { container, animationManager, rerender } = renderTestCase();

await animationManager.setAnimationProgress(0.5);
expect(getLine(container)).toHaveAttribute('stroke-dasharray', '50px 100px');

rerender(ChartWithLegend);
expect(getLine(container)).not.toHaveAttribute('stroke-dasharray', '0px 0px');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert preserved progress value, not only “not reset to zero.”

Line 613 and Line 623 only assert the value is not 0px 0px, which still allows partial regressions (e.g. dropping from 50px 100px to 10px 100px). For this regression test, assert preservation of the pre-rerender value.

Suggested fix
       await animationManager.setAnimationProgress(0.5);
-      expect(getLine(container)).toHaveAttribute('stroke-dasharray', '50px 100px');
+      const dashBeforeLegend = getLine(container).getAttribute('stroke-dasharray');
+      expect(dashBeforeLegend).toBe('50px 100px');

       rerender(ChartWithLegend);
-      expect(getLine(container)).not.toHaveAttribute('stroke-dasharray', '0px 0px');
+      expect(getLine(container)).toHaveAttribute('stroke-dasharray', dashBeforeLegend);

       await animationManager.setAnimationProgress(0.5);
-      expect(getLine(container)).toHaveAttribute('stroke-dasharray', '50px 100px');
+      const dashBeforeAutoYAxis = getLine(container).getAttribute('stroke-dasharray');
+      expect(dashBeforeAutoYAxis).toBe('50px 100px');

       rerender(ChartWithAutoYAxis);
-      expect(getLine(container)).not.toHaveAttribute('stroke-dasharray', '0px 0px');
+      expect(getLine(container)).toHaveAttribute('stroke-dasharray', dashBeforeAutoYAxis);

Also applies to: 616-624

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/cartesian/Line.animation.spec.tsx` around lines 606 - 614, The test
currently only asserts the stroke-dasharray is not "0px 0px" after rerender,
which allows partial regressions; change the assertion to capture the
pre-rerender value and assert it is preserved exactly after rerender.
Concretely, in the test "should not reset the visible stroke length when Legend
is added mid-animation" use getLine(container) to read and store the initial
stroke-dasharray after await animationManager.setAnimationProgress(0.5) (e.g.,
const initial = getLine(container).getAttribute('stroke-dasharray')), then call
rerender(ChartWithLegend) and assert
getLine(container).getAttribute('stroke-dasharray') === initial; apply the same
change to the other similar test block noted (lines 616-624).

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.05%. Comparing base (16d5b0d) to head (33783e5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7289   +/-   ##
=======================================
  Coverage   89.05%   89.05%           
=======================================
  Files         541      541           
  Lines       41088    41088           
  Branches     5564     5564           
=======================================
  Hits        36589    36589           
  Misses       4491     4491           
  Partials        8        8           

☔ 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

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.05%. Comparing base (16d5b0d) to head (862d359).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7289   +/-   ##
=======================================
  Coverage   89.05%   89.05%           
=======================================
  Files         541      541           
  Lines       41088    41088           
  Branches     5564     5564           
=======================================
  Hits        36589    36589           
  Misses       4491     4491           
  Partials        8        8           

☔ 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.

@github-actions

Copy link
Copy Markdown
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.

@codecov

codecov Bot commented May 1, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
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.

@PavelVanecek
PavelVanecek merged commit 02a29ec into main May 1, 2026
59 checks passed
@PavelVanecek
PavelVanecek deleted the line-animation-test branch May 1, 2026 12:39
@coderabbitai coderabbitai Bot mentioned this pull request May 22, 2026
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