test: cover legacy animation length changes#7283
Conversation
Co-authored-by: Copilot <[email protected]>
WalkthroughAdds 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
test/animation/legacyAnimationLengthChange.spec.tsx (3)
180-183: Add the3 -> 2shrink 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 index2.These tests assume the appended shape exists and immediately dereference
[2]. If the rerender stops producing the third item entirely, the failure becomes a genericundefinedaccess 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
createSelectorTestCaseto 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
📒 Files selected for processing (1)
test/animation/legacyAnimationLengthChange.spec.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🧹 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
setLengthChangeProgressandcompleteLengthChangeAnimationalready help with, with only the renderer, selector, and data direction changing. Folding them into a small helper orit.eachwould 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
📒 Files selected for processing (1)
test/animation/legacyAnimationLengthChange.spec.tsx
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Bundle ReportBundle size has no change ✅ |
Summary
Summary by CodeRabbit