Skip to content

Conversation

@ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Dec 12, 2025

Fix settings modal stories to properly query portal-rendered content.

Changes:

  • Use canvasElement.ownerDocument.body instead of document.body to scope queries to the Storybook iframe (not the parent UI)
  • Use findByRole with explicit names instead of finding all elements by role and filtering
  • Pre-set experiment state in localStorage for ExperimentsToggleOn story instead of clicking the toggle (more deterministic, avoids timing issues with localStorage → useSyncExternalStore → re-render in Chromatic)

Generated with mux

Select switches by name instead of DOM order to prevent flaky tests
when new switches are added to the Settings modal.

Also simplify ExperimentsToggleOff to show default state directly
rather than clicking twice (on then off).
Following ~/coder patterns - use screen for dialog/portal elements
instead of within(document.body). Simplifies the helper function.
@ethanndickson ethanndickson force-pushed the storybook-m122 branch 3 times, most recently from fa06207 to 1590636 Compare December 12, 2025 02:24
The 'screen' from @storybook/test queries the entire page including
Storybook UI, causing false matches on buttons like 'Experiments'
in the sidebar. Using canvasElement.ownerDocument.body scopes
queries to just the iframe content.
@ethanndickson ethanndickson added this pull request to the merge queue Dec 12, 2025
@ethanndickson ethanndickson removed this pull request from the merge queue due to a manual request Dec 12, 2025
@ethanndickson ethanndickson changed the title 🤖 fix: use aria-label to target experiment toggles in stories 🤖 fix: use ownerDocument.body for portal queries in settings stories Dec 12, 2025
@ethanndickson ethanndickson added this pull request to the merge queue Dec 12, 2025
Merged via the queue into main with commit e2f68eb Dec 12, 2025
20 checks passed
@ethanndickson ethanndickson deleted the storybook-m122 branch December 12, 2025 02:46
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