Skip to content

Commit

Permalink
add paparazzi tests for the DeleteAccountLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Mar 21, 2024
1 parent c150897 commit f1cfa8e
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ fun DeleteAccountLayout(state: State, modifier: Modifier = Modifier) {
Text(
stringResource(R.string.account_delete_description),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(horizontal = MARGIN_HORIZONTAL, top = 8.dp, bottom = 32.dp)
modifier = Modifier
.padding(horizontal = MARGIN_HORIZONTAL, top = 8.dp, bottom = 32.dp)
.align(Alignment.Start)
)

val actionsEnabled = state !is State.Deleting && state !is State.Error
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 25 additions & 9 deletions app/src/testDebug/kotlin/org/cru/godtools/ui/BasePaparazziTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.accessibility.AccessibilityRenderExtension
import com.android.ide.common.rendering.api.SessionParams.RenderingMode
import com.android.resources.NightMode
import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider
import kotlin.test.BeforeTest
import org.cru.godtools.base.ui.compose.LocalEventBus
import org.cru.godtools.base.ui.theme.GodToolsTheme
Expand All @@ -25,12 +26,20 @@ import org.junit.Assume.assumeFalse
import org.junit.Rule

abstract class BasePaparazziTest(
private val deviceConfig: DeviceConfig = DeviceConfig.NEXUS_5,
private val nightMode: NightMode = NightMode.NOTNIGHT,
private val accessibilityMode: AccessibilityMode = AccessibilityMode.NO_ACCESSIBILITY,
renderingMode: RenderingMode = RenderingMode.NORMAL,
private val excludeRedundantTests: Boolean = true,
private val eventBus: EventBus = EventBus(),
) {
protected class DeviceConfigProvider : TestParameterValuesProvider() {
override fun provideValues(context: Context?) = listOf(
value(DeviceConfig.NEXUS_5).withName("Nexus 5"),
// value(DeviceConfig.NEXUS_10.copy(orientation = ScreenOrientation.PORTRAIT)).withName("Nexus 10 Portrait"),
value(DeviceConfig.PIXEL_6_PRO).withName("Pixel 6 Pro"),
)
}
enum class AccessibilityMode { ACCESSIBILITY, NO_ACCESSIBILITY }

// HACK: workaround a "No OnBackPressedDispatcherOwner was provided via LocalOnBackPressedDispatcherOwner" error
Expand All @@ -41,7 +50,7 @@ abstract class BasePaparazziTest(

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5.copy(nightMode = nightMode),
deviceConfig = deviceConfig.copy(nightMode = nightMode),
renderingMode = when (accessibilityMode) {
AccessibilityMode.ACCESSIBILITY -> when (renderingMode) {
RenderingMode.SHRINK -> RenderingMode.NORMAL
Expand All @@ -60,23 +69,30 @@ abstract class BasePaparazziTest(
if (excludeRedundantTests) {
// don't run accessibility mode for night mode, we already test it for Not Night
assumeFalse(accessibilityMode == AccessibilityMode.ACCESSIBILITY && nightMode == NightMode.NIGHT)

// don't run accessibility mode for devices other than the NEXUS_5
assumeFalse(accessibilityMode == AccessibilityMode.ACCESSIBILITY && deviceConfig != DeviceConfig.NEXUS_5)
}
}

protected fun centerInSnapshot(content: @Composable BoxScope.() -> Unit) {
protected fun snapshot(content: @Composable () -> Unit) {
paparazzi.snapshot {
CompositionLocalProvider(
LocalEventBus provides eventBus,
LocalOnBackPressedDispatcherOwner provides backPressDispatcher
) {
GodToolsTheme {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.background(MaterialTheme.colorScheme.background),
content = content,
)
}
GodToolsTheme(content = content)
}
}
}

protected fun centerInSnapshot(content: @Composable BoxScope.() -> Unit) {
snapshot {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.background(MaterialTheme.colorScheme.background),
content = content,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cru.godtools.ui.account.delete

import app.cash.paparazzi.DeviceConfig
import com.android.resources.NightMode
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.slack.circuit.test.TestEventSink
import kotlin.test.Ignore
import kotlin.test.Test
import org.cru.godtools.ui.BasePaparazziTest
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class DeleteAccountLayoutPaparazziTest(
@TestParameter(valuesProvider = DeviceConfigProvider::class) deviceConfig: DeviceConfig,
@TestParameter nightMode: NightMode,
@TestParameter accessibilityMode: AccessibilityMode,
) : BasePaparazziTest(deviceConfig = deviceConfig, nightMode = nightMode, accessibilityMode = accessibilityMode) {
private val events = TestEventSink<DeleteAccountScreen.Event>()

@Test
fun `DeleteAccountLayout() - Display`() {
snapshot { DeleteAccountLayout(DeleteAccountScreen.State.Display(events)) }
}

@Test
fun `DeleteAccountLayout() - Deleting`() {
snapshot { DeleteAccountLayout(DeleteAccountScreen.State.Deleting(events)) }
}

@Test
@Ignore("TODO: Disabled due to https://github.com/cashapp/paparazzi/issues/1025")
fun `DeleteAccountLayout() - Error`() {
snapshot { DeleteAccountLayout(DeleteAccountScreen.State.Error(events)) }
}
}

0 comments on commit f1cfa8e

Please sign in to comment.