-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'takahirom/refactor-test/2024-12-12' into takahirom/add-…
…alertdialog-test/2024-11-15
- Loading branch information
Showing
3 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
78 changes: 78 additions & 0 deletions
78
sample-android/src/test/java/com/github/takahirom/roborazzi/sample/ComposeLambdaTest.kt
This file contains 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,78 @@ | ||
package com.github.takahirom.roborazzi.sample | ||
|
||
import android.app.Activity | ||
import android.graphics.Color | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.test.core.app.ActivityScenario | ||
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi | ||
import com.github.takahirom.roborazzi.RoborazziComposeActivityScenarioOption | ||
import com.github.takahirom.roborazzi.RoborazziComposeComposableOption | ||
import com.github.takahirom.roborazzi.RoborazziComposeOptions | ||
import com.github.takahirom.roborazzi.captureRoboImage | ||
import com.github.takahirom.roborazzi.fontScale | ||
import com.github.takahirom.roborazzi.roborazziSystemPropertyOutputDirectory | ||
import org.junit.Test | ||
|
||
class ComposeLambdaTest { | ||
@OptIn(ExperimentalRoborazziApi::class) | ||
@Test | ||
fun captureComposeLambdaImage() { | ||
captureRoboImage("${roborazziSystemPropertyOutputDirectory()}/manual_compose.png") { | ||
Text("Hello Compose!") | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalRoborazziApi::class) | ||
@Test | ||
fun captureComposeLambdaImageWithRoborazziComposeOptions() { | ||
captureRoboImage( | ||
"${roborazziSystemPropertyOutputDirectory()}/manual_compose_with_compose_options.png", | ||
roborazziComposeOptions = RoborazziComposeOptions { | ||
// We have several options to configure the test environment. | ||
fontScale(2f) | ||
|
||
/* | ||
We don't specify `localInspectionMode` by default. | ||
The default value for `localInspectionMode` in Compose is `false`. | ||
This is to maintain higher fidelity in tests. | ||
If you encounter issues integrating the library, you can set `localInspectionMode` to `true`. | ||
localInspectionMode(true) | ||
*/ | ||
|
||
// We can also configure the activity scenario and the composable content. | ||
addOption( | ||
object : RoborazziComposeComposableOption, | ||
RoborazziComposeActivityScenarioOption { | ||
override fun configureWithActivityScenario(scenario: ActivityScenario<out Activity>) { | ||
scenario.onActivity { | ||
it.window.decorView.setBackgroundColor(Color.BLUE) | ||
} | ||
} | ||
|
||
override fun configureWithComposable(content: @Composable () -> Unit): @Composable () -> Unit { | ||
return { | ||
Box( | ||
Modifier | ||
.padding(10.dp) | ||
.background(color = androidx.compose.ui.graphics.Color.Red) | ||
.padding(10.dp) | ||
) { | ||
content() | ||
} | ||
} | ||
} | ||
} | ||
) | ||
}, | ||
) { | ||
Text("Hello Compose!") | ||
} | ||
} | ||
} |
This file contains 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