Skip to content

Commit

Permalink
Add dialog color test
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Oct 24, 2024
1 parent 0f528a1 commit f2b823f
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ roborazzi-for-replacing-by-include-build = "1.0.0"
androidx-activity = "1.7.2"
androidx-appcompat = "1.7.0"
androidx-compose-material = "1.6.8"
androidx-compose-material3 = "1.2.1"
androidx-compose-material3 = "1.3.0"
androidx-compose-foundation = "1.6.8"
androidx-compose-runtime = "1.6.8"
androidx-compose-ui = "1.4.0"
Expand Down
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()
}
}
}

0 comments on commit f2b823f

Please sign in to comment.