Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2336a162 authored by Grace Cheng's avatar Grace Cheng
Browse files

Adding optional block to run before screenshot

Adding optional block to run viewModel config after view is created but
before screenshot is taken

Bug: 280354248
Change-Id: Ic28a6e0ab6e3de3ce6dd7ae8cea9a16963bac82f
parent 671d962a
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ open class ViewScreenshotTestRule(
    protected fun takeScreenshot(
        mode: Mode = Mode.WrapContent,
        viewProvider: (ComponentActivity) -> View,
        beforeScreenshot: (ComponentActivity) -> Unit = {}
    ): Bitmap {
        activityRule.scenario.onActivity { activity ->
            // Make sure that the activity draws full screen and fits the whole display instead of
@@ -94,6 +95,7 @@ open class ViewScreenshotTestRule(
            val content = activity.requireViewById<ViewGroup>(android.R.id.content)
            assertEquals(1, content.childCount)
            contentView = content.getChildAt(0)
            beforeScreenshot(activity)
        }

        return if (isRobolectric) {
@@ -111,9 +113,10 @@ open class ViewScreenshotTestRule(
    fun screenshotTest(
        goldenIdentifier: String,
        mode: Mode = Mode.WrapContent,
        viewProvider: (ComponentActivity) -> View,
        beforeScreenshot: (ComponentActivity) -> Unit = {},
        viewProvider: (ComponentActivity) -> View
    ) {
        val bitmap = takeScreenshot(mode, viewProvider)
        val bitmap = takeScreenshot(mode, viewProvider, beforeScreenshot)
        screenshotRule.assertBitmapAgainstGolden(
            bitmap,
            goldenIdentifier,