-
Notifications
You must be signed in to change notification settings - Fork 1
Add deterministic SimpleComponent screenshot test #99
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
Open
EmilioBejasa
wants to merge
9
commits into
main
Choose a base branch
from
deterministic-simple-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
985e994
experiment: eager story prep at configure() time
EmilioBejasa aa48c7c
fix: add ViewHelpers layout before Screenshot.snap on new arch
EmilioBejasa c573f41
fix: force software layer recursively before snapping screenshots
EmilioBejasa 0053212
Add deterministic SimpleComponent screenshot test
EmilioBejasa cbd0296
Fix missing ViewHelpers import in BaseStoryScreenshotTest
EmilioBejasa cec1935
ci: trigger CI
EmilioBejasa ec0c5f6
test: assert Fabric children mount only after two frames
EmilioBejasa ddcb25a
test: remove fabricChildrenMountedAfterTwoFrames
EmilioBejasa 658ddf5
Merge main into deterministic-simple-component
EmilioBejasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
android/app/src/androidTest/java/com/testapp/SimpleComponentScreenshotTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package com.testapp | ||
|
|
||
| import android.Manifest | ||
| import android.graphics.PixelFormat | ||
| import android.os.Handler | ||
| import android.os.Looper | ||
| import android.view.Choreographer | ||
| import android.view.ContextThemeWrapper | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.view.WindowManager | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.test.rule.GrantPermissionRule | ||
| import com.facebook.react.ReactApplication | ||
| import com.facebook.testing.screenshot.Screenshot | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import java.util.concurrent.CountDownLatch | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class SimpleComponentScreenshotTest { | ||
|
|
||
| @get:Rule | ||
| val permissionRule: GrantPermissionRule = GrantPermissionRule.grant( | ||
| Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
| Manifest.permission.READ_EXTERNAL_STORAGE, | ||
| Manifest.permission.SYSTEM_ALERT_WINDOW | ||
| ) | ||
|
|
||
| @Test | ||
| fun screenshotSimpleComponent() { | ||
| val instrumentation = InstrumentationRegistry.getInstrumentation() | ||
| val app = instrumentation.targetContext.applicationContext as ReactApplication | ||
| val reactHost = app.reactHost!! | ||
|
|
||
| val context = ContextThemeWrapper( | ||
| instrumentation.targetContext, | ||
| instrumentation.targetContext.applicationInfo.theme | ||
| ) | ||
| val surface = reactHost.createSurface(context, "SimpleComponent", null) | ||
| val view = surface.view | ||
| ?: throw IllegalStateException("ReactSurface returned a null view") | ||
|
|
||
| val wm = instrumentation.targetContext | ||
| .getSystemService(android.content.Context.WINDOW_SERVICE) as WindowManager | ||
| val params = WindowManager.LayoutParams( | ||
| 1080, 1920, | ||
| WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, | ||
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | ||
| PixelFormat.TRANSLUCENT | ||
| ) | ||
|
|
||
| instrumentation.runOnMainSync { | ||
| view.setLayerType(View.LAYER_TYPE_SOFTWARE, null) | ||
| wm.addView(view, params) | ||
| surface.start() | ||
| } | ||
|
|
||
| waitTwoFrames() | ||
|
|
||
| instrumentation.runOnMainSync { | ||
| setLayerTypeSoftwareRecursively(view) | ||
| Screenshot.snap(view).setName("simple_component").record() | ||
| } | ||
|
|
||
| instrumentation.runOnMainSync { | ||
| surface.stop() | ||
| wm.removeView(view) | ||
| } | ||
| } | ||
|
|
||
| private fun waitTwoFrames() { | ||
| repeat(2) { | ||
| val latch = CountDownLatch(1) | ||
| Handler(Looper.getMainLooper()).post { | ||
| Choreographer.getInstance().postFrameCallback { latch.countDown() } | ||
| } | ||
| latch.await() | ||
| } | ||
| } | ||
|
|
||
| private fun setLayerTypeSoftwareRecursively(view: View) { | ||
| view.setLayerType(View.LAYER_TYPE_SOFTWARE, null) | ||
| if (view is ViewGroup) { | ||
| for (i in 0 until view.childCount) { | ||
| setLayerTypeSoftwareRecursively(view.getChildAt(i)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
not deterministic