|
|
|
@ -16,13 +16,14 @@
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.ui
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
|
|
|
import androidx.compose.material3.SnackbarDuration.Indefinite
|
|
|
|
|
import androidx.compose.material3.SnackbarHostState
|
|
|
|
|
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
|
|
|
|
|
import androidx.compose.material3.windowsizeclass.WindowSizeClass
|
|
|
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
import androidx.compose.ui.platform.LocalInspectionMode
|
|
|
|
|
import androidx.compose.ui.test.DeviceConfigurationOverride
|
|
|
|
|
import androidx.compose.ui.test.ForcedSize
|
|
|
|
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
|
|
@ -30,10 +31,6 @@ import androidx.compose.ui.test.onRoot
|
|
|
|
|
import androidx.compose.ui.unit.Dp
|
|
|
|
|
import androidx.compose.ui.unit.DpSize
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
|
import androidx.work.Configuration
|
|
|
|
|
import androidx.work.testing.SynchronousExecutor
|
|
|
|
|
import androidx.work.testing.WorkManagerTestInitHelper
|
|
|
|
|
import com.github.takahirom.roborazzi.captureRoboImage
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository
|
|
|
|
@ -60,6 +57,7 @@ import org.robolectric.RobolectricTestRunner
|
|
|
|
|
import org.robolectric.annotation.Config
|
|
|
|
|
import org.robolectric.annotation.GraphicsMode
|
|
|
|
|
import org.robolectric.annotation.LooperMode
|
|
|
|
|
import java.util.TimeZone
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -112,17 +110,6 @@ class SnackbarScreenshotTests {
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setup() {
|
|
|
|
|
val config = Configuration.Builder()
|
|
|
|
|
.setMinimumLoggingLevel(Log.DEBUG)
|
|
|
|
|
.setExecutor(SynchronousExecutor())
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// Initialize WorkManager for instrumentation tests.
|
|
|
|
|
WorkManagerTestInitHelper.initializeTestWorkManager(
|
|
|
|
|
InstrumentationRegistry.getInstrumentation().context,
|
|
|
|
|
config,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
hiltRule.inject()
|
|
|
|
|
|
|
|
|
|
// Configure user data
|
|
|
|
@ -135,6 +122,12 @@ class SnackbarScreenshotTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setTimeZone() {
|
|
|
|
|
// Make time zone deterministic in tests
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun phone_noSnackbar() {
|
|
|
|
|
val snackbarHostState = SnackbarHostState()
|
|
|
|
@ -207,22 +200,27 @@ class SnackbarScreenshotTests {
|
|
|
|
|
) {
|
|
|
|
|
lateinit var scope: CoroutineScope
|
|
|
|
|
composeTestRule.setContent {
|
|
|
|
|
scope = rememberCoroutineScope()
|
|
|
|
|
|
|
|
|
|
DeviceConfigurationOverride(
|
|
|
|
|
DeviceConfigurationOverride.ForcedSize(DpSize(width, height)),
|
|
|
|
|
CompositionLocalProvider(
|
|
|
|
|
// Replaces images with placeholders
|
|
|
|
|
LocalInspectionMode provides true,
|
|
|
|
|
) {
|
|
|
|
|
BoxWithConstraints {
|
|
|
|
|
val appState = rememberNiaAppState(
|
|
|
|
|
windowSizeClass = WindowSizeClass.calculateFromSize(
|
|
|
|
|
DpSize(maxWidth, maxHeight),
|
|
|
|
|
),
|
|
|
|
|
networkMonitor = networkMonitor,
|
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
|
timeZoneMonitor = timeZoneMonitor,
|
|
|
|
|
)
|
|
|
|
|
NiaTheme {
|
|
|
|
|
NiaApp(appState, snackbarHostState, false, {}, {})
|
|
|
|
|
scope = rememberCoroutineScope()
|
|
|
|
|
|
|
|
|
|
DeviceConfigurationOverride(
|
|
|
|
|
DeviceConfigurationOverride.ForcedSize(DpSize(width, height)),
|
|
|
|
|
) {
|
|
|
|
|
BoxWithConstraints {
|
|
|
|
|
val appState = rememberNiaAppState(
|
|
|
|
|
windowSizeClass = WindowSizeClass.calculateFromSize(
|
|
|
|
|
DpSize(maxWidth, maxHeight),
|
|
|
|
|
),
|
|
|
|
|
networkMonitor = networkMonitor,
|
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
|
timeZoneMonitor = timeZoneMonitor,
|
|
|
|
|
)
|
|
|
|
|
NiaTheme {
|
|
|
|
|
NiaApp(appState, snackbarHostState, false, {}, {})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|