Skip to content

Conversation

jperals
Copy link
Member

@jperals jperals commented Sep 25, 2025

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 mocking HTMLElement.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 from window.getComputedStyle is subtracted from the zero width of the chart coming from getBoundingClientRect 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=165

The 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

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.14%. Comparing base (74732dd) to head (b4cd748).
⚠️ Report is 4 commits behind head on main.

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.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if (value === null) {
return <div ref={ref}>Loading...</div>;
return (
<div ref={ref} style={{ ...boxStyles, ...props.style }}>
Copy link
Member Author

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;
Copy link
Member Author

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

@jperals jperals marked this pull request as ready for review September 25, 2025 10:40
@jperals jperals requested a review from a team as a code owner September 25, 2025 10:40
@jperals jperals requested review from mariksav and removed request for a team September 25, 2025 10:40
@jperals jperals added this pull request to the merge queue Sep 29, 2025
Merged via the queue into main with commit a943c56 Sep 29, 2025
49 checks passed
@jperals jperals deleted the fix/resize-observer-border branch September 29, 2025 09:08
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.

2 participants