-
Notifications
You must be signed in to change notification settings - Fork 199
test: add more tests to FitPlugin #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
They cover the main use cases. More tests could be added in the future to cover special cases.
WalkthroughThe test suite for the Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm warn config production Use ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/__tests__/view/plugins/FitPlugin.test.ts (1)
20-189: Consider adding explanatory comments for complex expected values.While the test structure is excellent, the expected values in assertions (scales and translations) are complex calculations that would benefit from brief comments explaining how they were derived. This would improve maintainability and help future developers understand the test logic.
For example:
const scale = graph.getPlugin<FitPlugin>('fit').fitCenter(); +// Scale: min(16/1000, 16/1000) = 0.016 (pending verification) expect(scale).toBe(0.02);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/core/__tests__/view/plugins/FitPlugin.test.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/__tests__/view/plugins/FitPlugin.test.ts (1)
packages/core/src/view/plugins/FitPlugin.ts (1)
FitPlugin(87-281)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build (windows-2022)
- GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (11)
packages/core/__tests__/view/plugins/FitPlugin.test.ts (11)
18-18: LGTM: Appropriate import addition.The
Rectangleimport is correctly added to support the new test cases that need to set explicit graph bounds.
20-49: Well-designed helper function with good reusability.The
createContainerfunction effectively creates mock DOM elements with configurable dimension properties. The conditional property setting and use ofObject.definePropertywithconfigurable: trueare appropriate for testing scenarios.
51-60: Good baseline test for zero dimensions scenario.This test properly covers the edge case where graph dimensions are zero, verifying that the scale defaults to 1 and the expected translation values are applied.
78-92: Complex increased scale scenario with margin option.This test covers scaling up with a custom margin. The expected values (scale: 2.46, translation: 217, -59) should be verified against the fitCenter implementation to ensure the calculation logic is correct.
94-111: Good test for maxFitScale constraint.This test properly verifies that the
maxFitScaleproperty limits the scaling when the calculated scale would exceed the maximum. The setup and assertions are clear and appropriate.
113-121: Appropriate edge case test for fit method.This test correctly handles the scenario where both container and graph have zero dimensions, expecting no call to
scaleAndTranslatewhich aligns with the fit method's early return logic.
123-137: Test covers basic fit scaling scenario.The test uses
offsetWidth/offsetHeightproperties which are correct for thefitmethod. The expected scale and translation values should be validated against the fit implementation's complex calculation logic.
139-155: Good test for minFitScale constraint.This test effectively verifies the
minFitScaleproperty by using zero container dimensions which would normally result in an invalid scale, but the constraint ensures it's limited to 0.5.
157-171: Test covers increased scale scenario for fit method.Similar to the fitCenter tests, this covers scaling up when the container is larger than the graph. The calculations should be verified for accuracy.
173-189: Comprehensive test for maxFitScale in fit method.This test properly verifies that
maxFitScaleconstraints are respected in thefitmethod, maintaining consistency with thefitCentertests.
62-76:Details
❌ Incorrect review comment
Verify the scale calculation for decreased scale scenario.
The test expects a scale of 0.02, but let me verify this calculation:
- Container client dimensions: 20x20
- Default margin: 2
- Effective dimensions: (20-2*2) = 16x16
- Graph dimensions: 1000x1000
- Expected scale: min(16/1000, 16/1000) = 0.016
The expected scale of 0.02 seems inconsistent with this calculation.
🏁 Script executed:
#!/bin/bash # Verify the fitCenter calculation logic in the FitPlugin implementation echo "Checking fitCenter scale calculation logic..." ast-grep --pattern 'fitCenter($$$) { $$$ let newScale = $$$; $$$ }'Length of output: 176
🏁 Script executed:
#!/bin/bash # Locate FitPlugin source file fit_file=$(rg --files | grep 'FitPlugin.ts$' | head -n1) echo "FitPlugin file: $fit_file" echo "---- defaultOptions / margin ----" rg -n "defaultOptions" -C2 "$fit_file" echo echo "---- fitCenter implementation ----" rg -n "fitCenter" -C10 "$fit_file"Length of output: 3832
🏁 Script executed:
#!/bin/bash # Show implementation details around newScale in fitCenter rg -n fitCenter -C20 packages/core/src/view/plugins/FitPlugin.ts | sed -n '230,280p' rg -n "scaleAndTranslate" -C5 packages/core/src/view/plugins/FitPlugin.tsLength of output: 864
The test’s expected scale of 0.02 is correct.
The plugin applieskeep2digits(i.e.Number(value.toFixed(2))) after computing16/1000 = 0.016, which rounds to0.02. No change is needed.Likely an incorrect or invalid review comment.



They cover the main use cases. More tests could be added in the future to cover special cases.
Summary by CodeRabbit