-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
111 additions
and
1 deletion.
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
110 changes: 110 additions & 0 deletions
110
sample-android/src/test/java/com/github/takahirom/roborazzi/sample/SnapshotIssue.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,110 @@ | ||
package com.github.takahirom.roborazzi.sample | ||
|
||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.LocalTonalElevationEnabled | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.material3.lightColorScheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.isDialog | ||
import androidx.compose.ui.test.runComposeUiTest | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.github.takahirom.roborazzi.RoborazziOptions | ||
import com.github.takahirom.roborazzi.RoborazziRule | ||
import com.github.takahirom.roborazzi.RoborazziRule.Options | ||
import com.github.takahirom.roborazzi.captureRoboImage | ||
import com.github.takahirom.roborazzi.captureScreenRoboImage | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.annotation.GraphicsMode | ||
|
||
@GraphicsMode(GraphicsMode.Mode.NATIVE) | ||
@RunWith(AndroidJUnit4::class) | ||
@Config(qualifiers = "w360dp-h500dp") | ||
class SnapshotIssue { | ||
@get:Rule | ||
val roborazziRule = RoborazziRule( | ||
options = Options( | ||
roborazziOptions = RoborazziOptions( | ||
compareOptions = RoborazziOptions.CompareOptions( | ||
changeThreshold = 0.001F | ||
) | ||
) | ||
) | ||
) | ||
|
||
@Composable | ||
fun DialogContent() { | ||
AlertDialog( | ||
title = { Text("title") }, | ||
text = { Text("body") }, | ||
containerColor = Color.White, | ||
onDismissRequest = { }, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { }, | ||
) { | ||
Text("CANCEL") | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton( | ||
onClick = { }, | ||
) { | ||
Text("OK") | ||
} | ||
} | ||
) | ||
} | ||
|
||
@Composable | ||
fun WithMaterial3Theme(content: @Composable () -> Unit) { | ||
|
||
MaterialTheme( | ||
colorScheme = lightColorScheme( | ||
surface = Color.White, | ||
onSurface = Color.Black | ||
) | ||
) { | ||
content() | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
@Test | ||
fun withTonalElevationDefault() { | ||
runComposeUiTest { | ||
setContent { | ||
WithMaterial3Theme { | ||
DialogContent() | ||
} | ||
} | ||
|
||
onNode(isDialog()).captureRoboImage() | ||
captureScreenRoboImage() | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
@Test | ||
fun withTonalElevationDisabled() { | ||
runComposeUiTest { | ||
setContent { | ||
WithMaterial3Theme { | ||
CompositionLocalProvider(LocalTonalElevationEnabled provides true) { | ||
DialogContent() | ||
} | ||
} | ||
} | ||
|
||
onNode(isDialog()).captureRoboImage() | ||
captureScreenRoboImage() | ||
} | ||
} | ||
} |