-
Notifications
You must be signed in to change notification settings - Fork 196
chore: Mock getBoundingClientRect in mixed chart tests #3894
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3894 +/- ##
==========================================
- Coverage 97.15% 97.14% -0.01%
==========================================
Files 846 846
Lines 24592 24592
Branches 8680 8680
==========================================
- Hits 23892 23891 -1
- Misses 693 694 +1
Partials 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
if (value === null) { | ||
return <div ref={ref}>Loading...</div>; | ||
return ( | ||
<div ref={ref} style={{ ...boxStyles, ...props.style }}> |
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.
Use the same styles already in the initial render, because cloudscape-design/component-toolkit#165 applies to the initial render only.
window.getComputedStyle = fakeGetComputedStyle; | ||
HTMLElement.prototype.getBoundingClientRect = function () { | ||
const rect = originalBoundingClientRect.apply(this); | ||
rect.width = 900; |
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.
Smaller widths would cause less X ticks to appear in some of the tests
Description
This is necessary for cloudscape-design/component-toolkit#165.
JSDOM does not have access to actual element dimensions and returns 0 for everything. For this reason in the mixed chart tests we are mocking
window.getComputedStyle
to return 2px for border width among other things. But we are not mockingHTMLElement.prototype.getBoundingClientRect
, so these tests still assume that all values are 0 for the values that this function returns. Then the changes in cloudscape-design/component-toolkit#165 causes the calculated dimensions of the chart to be negative, because a non-zero border coming fromwindow.getComputedStyle
is subtracted from the zero width of the chart coming fromgetBoundingClientRect
here (which in reality won't happen, because these calculated dimensions should include the border). And these negative dimension values causes the chart not to render expected inner elements: https://github.com/cloudscape-design/component-toolkit/actions/runs/17982007963/job/51205514110?pr=165The solution is to add one more mock for component-toolkit's
useContainerQuery
, which is used by the chart to determine its width.How has this been tested?
Ran the test with cloudscape-design/component-toolkit#165 applied to the local copy of component-toolkit. The tests only passed after the changes in this PR.
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Security
checkSafeUrl
function.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.