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.RecordOptions
import com.github.takahirom.roborazzi.captureRoboImage
import com.google.accompanist.testharness.TestHarness
import org.robolectric.RuntimeEnvironment
val DefaultRoborazziOptions =
@ -36,16 +37,17 @@ val DefaultRoborazziOptions =
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(
screenshotName: String,
body: @Composable () -> Unit,
) {
listOf(
"phone" to "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480",
"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)
DefaultTestDevices.values().forEach {
this.captureForDevice(it.description, it.spec, screenshotName, body = body)
}
}
@ -53,8 +55,9 @@ fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.c
deviceName: String,
deviceSpec: String,
screenshotName: String,
body: @Composable () -> Unit,
roborazziOptions: RoborazziOptions = DefaultRoborazziOptions,
darkMode: Boolean = false,
body: @Composable () -> Unit,
) {
val (width, height, dpi) = extractSpecs(deviceSpec)
@ -65,9 +68,11 @@ fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.c
CompositionLocalProvider(
LocalInspectionMode provides true,
) {
TestHarness(darkMode = darkMode) {
body()
}
}
}
this.onRoot()
.captureRoboImage(
"src/test/screenshots/${screenshotName}_$deviceName.png",

@ -17,14 +17,19 @@
package com.google.samples.apps.nowinandroid.feature.foryou
import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
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.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.ui.NewsFeedUiState
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.feature.foryou.OnboardingUiState.Loading
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 org.junit.Before
import org.junit.Rule
@ -60,7 +65,7 @@ class ForYouScreenScreenshotTests {
}
@Test
fun testForYouScreenPopulatedFeed() {
fun forYouScreenPopulatedFeed() {
composeTestRule.captureMultiDevice("ForYouScreenPopulatedFeed") {
NiaTheme {
ForYouScreen(
@ -82,7 +87,7 @@ class ForYouScreenScreenshotTests {
}
@Test
fun testForYouScreenLoading() {
fun forYouScreenLoading() {
composeTestRule.captureMultiDevice("ForYouScreenLoading") {
NiaTheme {
ForYouScreen(
@ -102,16 +107,54 @@ class ForYouScreenScreenshotTests {
}
@Test
fun testForYouScreenTopicSelection() {
fun 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 {
NiaBackground {
ForYouScreen(
isSyncing = false,
onboardingUiState = OnboardingUiState.Shown(
onboardingUiState = Shown(
topics = userNewsResources.flatMap { news -> news.followableTopics }
.distinctBy { it.topic.id },
),
feedState = NewsFeedUiState.Success(
feedState = Success(
feed = userNewsResources,
),
onTopicCheckedChanged = { _, _ -> },
@ -126,14 +169,15 @@ class ForYouScreenScreenshotTests {
}
}
@Test
fun testForYouScreenPopulatedAndLoading() {
composeTestRule.captureMultiDevice("ForYouScreenPopulatedAndLoading") {
@Composable
private fun ForYouScreenPopulatedAndLoading() {
NiaTheme {
NiaBackground {
NiaTheme {
ForYouScreen(
isSyncing = true,
onboardingUiState = OnboardingUiState.Loading,
feedState = NewsFeedUiState.Success(
onboardingUiState = Loading,
feedState = Success(
feed = userNewsResources,
),
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