Skip to content

Add isolated component screenshot tests for all story variants#105

Open
EmilioBejasa wants to merge 5 commits intomainfrom
component-surface-screenshot-tests
Open

Add isolated component screenshot tests for all story variants#105
EmilioBejasa wants to merge 5 commits intomainfrom
component-surface-screenshot-tests

Conversation

@EmilioBejasa
Copy link
Copy Markdown
Collaborator

Summary

  • Adds ReactHostFixture singleton so DefaultComponentsRegistry.register (a JNI native call) is only invoked once per process
  • Adds ComponentSurfaceTest parameterized over 25 story variants across all 6 components, matching the exact prop states from .stories.tsx files
  • Simplifies IsolatedTest to delegate to the shared fixture
  • Uses ReactMarker.CONTENT_APPEARED to reliably wait for React to render (fixes timeout issue with viewTreeObserver)
  • Uses ContextThemeWrapper(AppTheme) so Android widgets like Switch get their styled drawables (fixes NPE crash)
  • Registers all story variant components in index.js

Test plan

  • All 26 screenshots record successfully locally (app:recordDebugAndroidTestScreenshotTest)
  • CI passes

🤖 Generated with Claude Code

EmilioBejasa and others added 5 commits April 3, 2026 12:22
…tion

Removes dependency on MainApplication by constructing ReactHostImpl
directly in the test with dev support and packager access disabled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace ViewHelpers.setupView with WindowManager.TYPE_APPLICATION_OVERLAY
  so Fabric's Choreographer can fire mutations against a real Window
- Add reactHost.onHostResume(null) so Fabric commits its render tree
  (without RESUMED lifecycle state, all mutations are silently dropped)
- Wait for ReactMarkerConstants.CONTENT_APPEARED before snapping screenshot
- Set software layer type so Screenshot.snap() can capture via draw(canvas)
- Grant SYSTEM_ALERT_WINDOW permission required for overlay window type

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Prevents checkered (transparent) background in captured screenshots.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the TYPE_APPLICATION_OVERLAY window (which required
SYSTEM_ALERT_WINDOW permission) with WindowAttachment.dispatchAttach,
which fakes window attachment via reflection without a real window.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ReactHostFixture: shared singleton ReactHostImpl so DefaultComponentsRegistry.register
  is only called once per process
- ComponentSurfaceTest: parameterized over 25 story variants (Button, Header,
  MyFeature, SwitchFeature, TimerFeature, CoinFlipFeature) matching story prop states
- IsolatedTest: simplified to delegate to ReactHostFixture.screenshotComponent
- Uses ReactMarker.CONTENT_APPEARED to reliably wait for React render
- Uses ContextThemeWrapper(AppTheme) so Android widgets (Switch) get styled drawables
- Registers all story variant components in index.js

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@EmilioBejasa EmilioBejasa requested a review from tdrhq April 7, 2026 18:32

var detacher: WindowAttachment.Detacher? = null

try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after PR #103 is merged, don't duplicate the code. Instead, refactor the code out of IsolatedTest and reuse it.

Don't send me this PR until we're happy with #103 though

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