Skip to content

test: cover legacy animation length changes#7283

Merged
PavelVanecek merged 2 commits into
mainfrom
legacy-animation-length-change-tests
Apr 28, 2026
Merged

test: cover legacy animation length changes#7283
PavelVanecek merged 2 commits into
mainfrom
legacy-animation-length-change-tests

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a regression suite for legacy animation behavior when data length changes
  • cover Area, Bar, Funnel, Line, Scatter, Pie, Radar, and RadialBar
  • lock down the historical defaults that the new animationMatchBy prop should preserve

Summary by CodeRabbit

  • Tests
    • Added comprehensive regression tests for chart animations when data length changes between renders (both increases and decreases). Verifies mid-animation geometry and sizing across Area, Line, Radar, Bar, Funnel, Scatter, Pie, and RadialBar charts to ensure appended items grow from zero and removed items collapse, with proportional/intermediate positions and sizes validated.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a comprehensive Vitest suite that exercises legacy animation behavior across eight chart types when rendered data length increases or decreases, sampling mid-animation state and asserting geometry/attribute expectations.

Changes

Cohort / File(s) Summary
Animation Regression Tests
test/animation/legacyAnimationLengthChange.spec.tsx
New ~600-line test file adding end-to-end animation tests for Area, Line, Radar, Bar, Funnel, Scatter, Pie, and RadialBar. Tests render charts, advance/complete animations, sample mid-animation geometry/attributes (paths, points, sizes), and assert expected behaviors for appended vs removed items; attention: many custom test shapes/hooks and precise SVG geometry assertions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete; it lacks required sections such as Related Issue, Motivation and Context, How Has This Been Tested, and Types of changes checkboxes specified in the template. Complete the description by adding all required template sections: Related Issue, Motivation and Context, How Has This Been Tested, Screenshots (if appropriate), Types of changes, and Checklist items.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: cover legacy animation length changes' accurately and concisely describes the main change—adding test coverage for legacy animation behavior when data length changes.
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 legacy-animation-length-change-tests

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.

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

🧹 Nitpick comments (3)
test/animation/legacyAnimationLengthChange.spec.tsx (3)

180-183: Add the 3 -> 2 shrink path to this suite too.

Everything here exercises 2 -> 3, so the removal branch of the legacy matching logic is still unprotected. Length decreases often take a different path than appended-item growth, and that seems in scope for a “length change” regression suite.

Also applies to: 185-429

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

In `@test/animation/legacyAnimationLengthChange.spec.tsx` around lines 180 - 183,
Add test cases that exercise the shrink path (3 -> 2) in the same suite so the
removal branch of the legacy matching logic is covered: create equivalents to
the existing growth tests but initialize with largeData/largePolarData and
transition to smallData/smallPolarData (the variables smallData, largeData,
smallPolarData, largePolarData are present) and run the same assertions and
animation checks used for the 2 -> 3 path; ensure these new tests mirror the
setup/teardown and expectation logic (e.g., legacy matching/cleanup assertions)
used elsewhere in this spec so the removal branch is executed.

272-279: Assert the captured item count before reading index 2.

These tests assume the appended shape exists and immediately dereference [2]. If the rerender stops producing the third item entirely, the failure becomes a generic undefined access instead of clearly showing that the appended element was never rendered.

Suggested assertion pattern
     await renderResult.animationManager.setAnimationProgress(0.5);
     const midBars = getCapturedBars(renderResult.container);
     await renderResult.animationManager.completeAnimation();
     const finalBars = getCapturedBars(renderResult.container);

+    expect(midBars).toHaveLength(3);
+    expect(finalBars).toHaveLength(3);
     const midBar = midBars[2];
     const finalBar = finalBars[2];

Also applies to: 314-315, 349-350, 386-387, 422-423

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

In `@test/animation/legacyAnimationLengthChange.spec.tsx` around lines 272 - 279,
Add explicit assertions that the captured arrays contain at least three items
before dereferencing index 2: after calling
renderResult.animationManager.setAnimationProgress(...) and after
completeAnimation() assert the lengths of the arrays returned by
getCapturedBars(renderResult.container) (and the other captured lists at the
other locations) are >= 3 so that reading midBars[2] and finalBars[2] fails with
a clear test assertion when the appended element is missing; update each
occurrence (the pairs around setAnimationProgress/completeAnimation shown and
the other locations mentioned) to perform this pre-check using the test
framework's assert/expect API.

185-429: Track selector churn across these rerenders as well.

The geometry checks are good, but this suite never asserts how many selector recalculations happen during the length-change rerender. That leaves a performance regression path open even if the sampled animation state stays correct. As per coding guidelines, "Verify the number of selector calls using the spy object from createSelectorTestCase to spot unnecessary re-renders and improve performance".

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

In `@test/animation/legacyAnimationLengthChange.spec.tsx` around lines 185 - 429,
Add assertions that verify selector call counts using the spy from
createSelectorTestCase around the length-change rerenders: wrap the initial
render and the rerender (or the primeAndRerender flow) with
createSelectorTestCase to obtain selectorSpy, then assert selectorSpy.callCount
(or individual selectorSpy.getCallCount) before and after the rerender in each
relevant spec (those using rechartsTestRender and primeAndRerender, e.g., the
Area, Line, Radar, Bar, Funnel, Scatter, Pie, and RadialBar tests), ensuring you
check that only the expected minimal number of selector recalculations occurred
during animationManager.setAnimationProgress and completeAnimation. Use the
existing test helpers (createSelectorTestCase, selectorSpy, primeAndRerender,
rechartsTestRender, animationManager) to locate the insertion points and keep
the assertions tight to avoid false positives.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/animation/legacyAnimationLengthChange.spec.tsx`:
- Around line 180-183: Add test cases that exercise the shrink path (3 -> 2) in
the same suite so the removal branch of the legacy matching logic is covered:
create equivalents to the existing growth tests but initialize with
largeData/largePolarData and transition to smallData/smallPolarData (the
variables smallData, largeData, smallPolarData, largePolarData are present) and
run the same assertions and animation checks used for the 2 -> 3 path; ensure
these new tests mirror the setup/teardown and expectation logic (e.g., legacy
matching/cleanup assertions) used elsewhere in this spec so the removal branch
is executed.
- Around line 272-279: Add explicit assertions that the captured arrays contain
at least three items before dereferencing index 2: after calling
renderResult.animationManager.setAnimationProgress(...) and after
completeAnimation() assert the lengths of the arrays returned by
getCapturedBars(renderResult.container) (and the other captured lists at the
other locations) are >= 3 so that reading midBars[2] and finalBars[2] fails with
a clear test assertion when the appended element is missing; update each
occurrence (the pairs around setAnimationProgress/completeAnimation shown and
the other locations mentioned) to perform this pre-check using the test
framework's assert/expect API.
- Around line 185-429: Add assertions that verify selector call counts using the
spy from createSelectorTestCase around the length-change rerenders: wrap the
initial render and the rerender (or the primeAndRerender flow) with
createSelectorTestCase to obtain selectorSpy, then assert selectorSpy.callCount
(or individual selectorSpy.getCallCount) before and after the rerender in each
relevant spec (those using rechartsTestRender and primeAndRerender, e.g., the
Area, Line, Radar, Bar, Funnel, Scatter, Pie, and RadialBar tests), ensuring you
check that only the expected minimal number of selector recalculations occurred
during animationManager.setAnimationProgress and completeAnimation. Use the
existing test helpers (createSelectorTestCase, selectorSpy, primeAndRerender,
rechartsTestRender, animationManager) to locate the insertion points and keep
the assertions tight to avoid false positives.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14e6c1f2-13b9-427f-a376-2c2d8f459a56

📥 Commits

Reviewing files that changed from the base of the PR and between 5fcd09d and 0ab13ac.

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

@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.05%. Comparing base (5fcd09d) to head (9a5c391).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7283   +/-   ##
=======================================
  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.

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

🧹 Nitpick comments (1)
test/animation/legacyAnimationLengthChange.spec.tsx (1)

293-355: Consider table-driving the Area/Line curve cases.

These four tests repeat the same flow that setLengthChangeProgress and completeLengthChangeAnimation already help with, with only the renderer, selector, and data direction changing. Folding them into a small helper or it.each would reduce copy/paste drift.

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

In `@test/animation/legacyAnimationLengthChange.spec.tsx` around lines 293 - 355,
The four tests ('Area uses the final curve geometry immediately when data length
increases/decreases' and 'Line ...') duplicate the same flow; refactor them into
a table-driven test (it.each or a small helper) that iterates over
renderer/selector/data pairs to avoid copy/paste. Use the existing helpers
setLengthChangeProgress and completeLengthChangeAnimation and the spy helper
renderChartWithSelectorSpy, and parameterize the renderer functions
(renderAreaChart, renderLineChart), the selector strings
('.recharts-area-curve', '.recharts-line-curve'), and data directions
(smallData→largeData vs largeData→smallData) while keeping assertions that
initialCurve !== finalCurve and midCurve === finalCurve via getCurvePoints.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/animation/legacyAnimationLengthChange.spec.tsx`:
- Around line 293-355: The four tests ('Area uses the final curve geometry
immediately when data length increases/decreases' and 'Line ...') duplicate the
same flow; refactor them into a table-driven test (it.each or a small helper)
that iterates over renderer/selector/data pairs to avoid copy/paste. Use the
existing helpers setLengthChangeProgress and completeLengthChangeAnimation and
the spy helper renderChartWithSelectorSpy, and parameterize the renderer
functions (renderAreaChart, renderLineChart), the selector strings
('.recharts-area-curve', '.recharts-line-curve'), and data directions
(smallData→largeData vs largeData→smallData) while keeping assertions that
initialCurve !== finalCurve and midCurve === finalCurve via getCurvePoints.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: afba90b6-8170-4d5e-a889-d0f93d9038c7

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab13ac and 9a5c391.

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

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

@PavelVanecek
PavelVanecek merged commit 7dee885 into main Apr 28, 2026
58 checks passed
@PavelVanecek
PavelVanecek deleted the legacy-animation-length-change-tests branch April 28, 2026 15:09
@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

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