Adds dark screenshot tests and fixes background colors in ForYou (#918)

* Adds dark screenshot tests and fixes background colors in ForYou

* 🤖 Updates screenshots
pull/907/head
Jose Alcérreca 1 year ago committed by GitHub
parent 851ca6388e
commit 5b79869324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,6 +28,7 @@ import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.RoborazziOptions.CompareOptions import com.github.takahirom.roborazzi.RoborazziOptions.CompareOptions
import com.github.takahirom.roborazzi.RoborazziOptions.RecordOptions import com.github.takahirom.roborazzi.RoborazziOptions.RecordOptions
import com.github.takahirom.roborazzi.captureRoboImage import com.github.takahirom.roborazzi.captureRoboImage
import com.google.accompanist.testharness.TestHarness
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
val DefaultRoborazziOptions = val DefaultRoborazziOptions =
@ -36,16 +37,17 @@ val DefaultRoborazziOptions =
recordOptions = RecordOptions(resizeScale = 0.5), // Reduce the size of the PNGs recordOptions = RecordOptions(resizeScale = 0.5), // Reduce the size of the PNGs
) )
enum class DefaultTestDevices(val description: String, val spec: String) {
PHONE("phone", "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480"),
FOLDABLE("foldable", "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480"),
TABLET("tablet", "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480"),
}
fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.captureMultiDevice( fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.captureMultiDevice(
screenshotName: String, screenshotName: String,
body: @Composable () -> Unit, body: @Composable () -> Unit,
) { ) {
listOf( DefaultTestDevices.values().forEach {
"phone" to "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480", this.captureForDevice(it.description, it.spec, screenshotName, body = body)
"foldable" to "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480",
"tablet" to "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480",
).forEach {
this.captureForDevice(it.first, it.second, screenshotName, body)
} }
} }
@ -53,8 +55,9 @@ fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.c
deviceName: String, deviceName: String,
deviceSpec: String, deviceSpec: String,
screenshotName: String, screenshotName: String,
body: @Composable () -> Unit,
roborazziOptions: RoborazziOptions = DefaultRoborazziOptions, roborazziOptions: RoborazziOptions = DefaultRoborazziOptions,
darkMode: Boolean = false,
body: @Composable () -> Unit,
) { ) {
val (width, height, dpi) = extractSpecs(deviceSpec) val (width, height, dpi) = extractSpecs(deviceSpec)
@ -65,9 +68,11 @@ fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.c
CompositionLocalProvider( CompositionLocalProvider(
LocalInspectionMode provides true, LocalInspectionMode provides true,
) { ) {
TestHarness(darkMode = darkMode) {
body() body()
} }
} }
}
this.onRoot() this.onRoot()
.captureRoboImage( .captureRoboImage(
"src/test/screenshots/${screenshotName}_$deviceName.png", "src/test/screenshots/${screenshotName}_$deviceName.png",

@ -17,14 +17,19 @@
package com.google.samples.apps.nowinandroid.feature.foryou package com.google.samples.apps.nowinandroid.feature.foryou
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackground
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultTestDevices
import com.google.samples.apps.nowinandroid.core.testing.util.captureForDevice
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiDevice import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiDevice
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success
import com.google.samples.apps.nowinandroid.core.ui.UserNewsResourcePreviewParameterProvider import com.google.samples.apps.nowinandroid.core.ui.UserNewsResourcePreviewParameterProvider
import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.Loading import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.Loading
import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.NotShown import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.NotShown
import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.Shown
import dagger.hilt.android.testing.HiltTestApplication import dagger.hilt.android.testing.HiltTestApplication
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -60,7 +65,7 @@ class ForYouScreenScreenshotTests {
} }
@Test @Test
fun testForYouScreenPopulatedFeed() { fun forYouScreenPopulatedFeed() {
composeTestRule.captureMultiDevice("ForYouScreenPopulatedFeed") { composeTestRule.captureMultiDevice("ForYouScreenPopulatedFeed") {
NiaTheme { NiaTheme {
ForYouScreen( ForYouScreen(
@ -82,7 +87,7 @@ class ForYouScreenScreenshotTests {
} }
@Test @Test
fun testForYouScreenLoading() { fun forYouScreenLoading() {
composeTestRule.captureMultiDevice("ForYouScreenLoading") { composeTestRule.captureMultiDevice("ForYouScreenLoading") {
NiaTheme { NiaTheme {
ForYouScreen( ForYouScreen(
@ -102,16 +107,54 @@ class ForYouScreenScreenshotTests {
} }
@Test @Test
fun testForYouScreenTopicSelection() { fun forYouScreenTopicSelection() {
composeTestRule.captureMultiDevice("ForYouScreenTopicSelection") { composeTestRule.captureMultiDevice("ForYouScreenTopicSelection") {
ForYouScreenTopicSelection()
}
}
@Test
fun forYouScreenTopicSelection_dark() {
composeTestRule.captureForDevice(
deviceName = "phone_dark",
deviceSpec = DefaultTestDevices.PHONE.spec,
screenshotName = "ForYouScreenTopicSelection",
darkMode = true,
) {
ForYouScreenTopicSelection()
}
}
@Test
fun forYouScreenPopulatedAndLoading() {
composeTestRule.captureMultiDevice("ForYouScreenPopulatedAndLoading") {
ForYouScreenPopulatedAndLoading()
}
}
@Test
fun forYouScreenPopulatedAndLoading_dark() {
composeTestRule.captureForDevice(
deviceName = "phone_dark",
deviceSpec = DefaultTestDevices.PHONE.spec,
screenshotName = "ForYouScreenPopulatedAndLoading",
darkMode = true,
) {
ForYouScreenPopulatedAndLoading()
}
}
@Composable
private fun ForYouScreenTopicSelection() {
NiaTheme { NiaTheme {
NiaBackground {
ForYouScreen( ForYouScreen(
isSyncing = false, isSyncing = false,
onboardingUiState = OnboardingUiState.Shown( onboardingUiState = Shown(
topics = userNewsResources.flatMap { news -> news.followableTopics } topics = userNewsResources.flatMap { news -> news.followableTopics }
.distinctBy { it.topic.id }, .distinctBy { it.topic.id },
), ),
feedState = NewsFeedUiState.Success( feedState = Success(
feed = userNewsResources, feed = userNewsResources,
), ),
onTopicCheckedChanged = { _, _ -> }, onTopicCheckedChanged = { _, _ -> },
@ -126,14 +169,15 @@ class ForYouScreenScreenshotTests {
} }
} }
@Test @Composable
fun testForYouScreenPopulatedAndLoading() { private fun ForYouScreenPopulatedAndLoading() {
composeTestRule.captureMultiDevice("ForYouScreenPopulatedAndLoading") { NiaTheme {
NiaBackground {
NiaTheme { NiaTheme {
ForYouScreen( ForYouScreen(
isSyncing = true, isSyncing = true,
onboardingUiState = OnboardingUiState.Loading, onboardingUiState = Loading,
feedState = NewsFeedUiState.Success( feedState = Success(
feed = userNewsResources, feed = userNewsResources,
), ),
onTopicCheckedChanged = { _, _ -> }, onTopicCheckedChanged = { _, _ -> },
@ -148,3 +192,4 @@ class ForYouScreenScreenshotTests {
} }
} }
} }
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

After

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Loading…
Cancel
Save