|
|
|
@ -32,14 +32,10 @@ import androidx.compose.foundation.layout.windowInsetsEndWidth
|
|
|
|
|
import androidx.compose.foundation.layout.windowInsetsPadding
|
|
|
|
|
import androidx.compose.foundation.layout.windowInsetsStartWidth
|
|
|
|
|
import androidx.compose.foundation.layout.windowInsetsTopHeight
|
|
|
|
|
import androidx.compose.material3.SnackbarDuration.Indefinite
|
|
|
|
|
import androidx.compose.material3.SnackbarHostState
|
|
|
|
|
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
|
|
|
|
|
import androidx.compose.material3.adaptive.Posture
|
|
|
|
|
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
@ -68,15 +64,15 @@ import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.util.TimeZoneMonitor
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor
|
|
|
|
|
import com.google.samples.apps.nowinandroid.uitesthiltmanifest.HiltComponentActivity
|
|
|
|
|
import dagger.hilt.android.testing.BindValue
|
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidRule
|
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidTest
|
|
|
|
|
import dagger.hilt.android.testing.HiltTestApplication
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.flow.first
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
import org.junit.After
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
@ -121,8 +117,7 @@ class SnackbarInsetsScreenshotTests {
|
|
|
|
|
@get:Rule(order = 2)
|
|
|
|
|
val composeTestRule = createAndroidComposeRule<HiltComponentActivity>()
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
lateinit var networkMonitor: NetworkMonitor
|
|
|
|
|
private lateinit var networkMonitor: NetworkMonitor
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
lateinit var timeZoneMonitor: TimeZoneMonitor
|
|
|
|
@ -140,6 +135,9 @@ class SnackbarInsetsScreenshotTests {
|
|
|
|
|
fun setup() {
|
|
|
|
|
hiltRule.inject()
|
|
|
|
|
|
|
|
|
|
// Set network connection to online
|
|
|
|
|
networkMonitor = TestNetworkMonitor().apply { setConnected(true) }
|
|
|
|
|
|
|
|
|
|
// Configure user data
|
|
|
|
|
runBlocking {
|
|
|
|
|
userDataRepository.setShouldHideOnboarding(true)
|
|
|
|
@ -156,85 +154,63 @@ class SnackbarInsetsScreenshotTests {
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
fun resetConnectionOnline() {
|
|
|
|
|
networkMonitor = TestNetworkMonitor().apply { setConnected(true) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun phone_noSnackbar() {
|
|
|
|
|
val snackbarHostState = SnackbarHostState()
|
|
|
|
|
testSnackbarScreenshotWithSize(
|
|
|
|
|
snackbarHostState,
|
|
|
|
|
400.dp,
|
|
|
|
|
500.dp,
|
|
|
|
|
"insets_snackbar_compact_medium_noSnackbar",
|
|
|
|
|
action = { },
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun snackbarShown_phone() {
|
|
|
|
|
val snackbarHostState = SnackbarHostState()
|
|
|
|
|
// Set network connection to offline
|
|
|
|
|
networkMonitor = TestNetworkMonitor().apply { setConnected(false) }
|
|
|
|
|
testSnackbarScreenshotWithSize(
|
|
|
|
|
snackbarHostState,
|
|
|
|
|
400.dp,
|
|
|
|
|
500.dp,
|
|
|
|
|
"insets_snackbar_compact_medium",
|
|
|
|
|
) {
|
|
|
|
|
snackbarHostState.showSnackbar(
|
|
|
|
|
"This is a test snackbar message",
|
|
|
|
|
actionLabel = "Action Label",
|
|
|
|
|
duration = Indefinite,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun snackbarShown_foldable() {
|
|
|
|
|
val snackbarHostState = SnackbarHostState()
|
|
|
|
|
// Set network connection to offline
|
|
|
|
|
networkMonitor = TestNetworkMonitor().apply { setConnected(false) }
|
|
|
|
|
testSnackbarScreenshotWithSize(
|
|
|
|
|
snackbarHostState,
|
|
|
|
|
600.dp,
|
|
|
|
|
600.dp,
|
|
|
|
|
"insets_snackbar_medium_medium",
|
|
|
|
|
) {
|
|
|
|
|
snackbarHostState.showSnackbar(
|
|
|
|
|
"This is a test snackbar message",
|
|
|
|
|
actionLabel = "Action Label",
|
|
|
|
|
duration = Indefinite,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun snackbarShown_tablet() {
|
|
|
|
|
val snackbarHostState = SnackbarHostState()
|
|
|
|
|
// Set network connection to offline
|
|
|
|
|
networkMonitor = TestNetworkMonitor().apply { setConnected(false) }
|
|
|
|
|
testSnackbarScreenshotWithSize(
|
|
|
|
|
snackbarHostState,
|
|
|
|
|
900.dp,
|
|
|
|
|
900.dp,
|
|
|
|
|
"insets_snackbar_expanded_expanded",
|
|
|
|
|
) {
|
|
|
|
|
snackbarHostState.showSnackbar(
|
|
|
|
|
"This is a test snackbar message",
|
|
|
|
|
actionLabel = "Action Label",
|
|
|
|
|
duration = Indefinite,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
|
|
|
|
|
private fun testSnackbarScreenshotWithSize(
|
|
|
|
|
snackbarHostState: SnackbarHostState,
|
|
|
|
|
width: Dp,
|
|
|
|
|
height: Dp,
|
|
|
|
|
screenshotName: String,
|
|
|
|
|
action: suspend () -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
lateinit var scope: CoroutineScope
|
|
|
|
|
composeTestRule.setContent {
|
|
|
|
|
CompositionLocalProvider(
|
|
|
|
|
// Replaces images with placeholders
|
|
|
|
|
LocalInspectionMode provides true,
|
|
|
|
|
) {
|
|
|
|
|
scope = rememberCoroutineScope()
|
|
|
|
|
|
|
|
|
|
DeviceConfigurationOverride(
|
|
|
|
|
DeviceConfigurationOverride.ForcedSize(DpSize(width, height)),
|
|
|
|
|
) {
|
|
|
|
@ -269,12 +245,9 @@ class SnackbarInsetsScreenshotTests {
|
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
|
timeZoneMonitor = timeZoneMonitor,
|
|
|
|
|
)
|
|
|
|
|
// Replace NiaApp for using Background, which contains SnackBar
|
|
|
|
|
NiaApp(
|
|
|
|
|
appState = appState,
|
|
|
|
|
snackbarHostState = snackbarHostState,
|
|
|
|
|
showSettingsDialog = false,
|
|
|
|
|
onSettingsDismissed = {},
|
|
|
|
|
onTopAppBarActionClick = {},
|
|
|
|
|
windowAdaptiveInfo = WindowAdaptiveInfo(
|
|
|
|
|
windowSizeClass = WindowSizeClass.compute(
|
|
|
|
|
maxWidth.value,
|
|
|
|
@ -291,10 +264,6 @@ class SnackbarInsetsScreenshotTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.launch {
|
|
|
|
|
action()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithTag("root")
|
|
|
|
|
.captureRoboImage(
|
|
|
|
|
"src/testDemo/screenshots/$screenshotName.png",
|
|
|
|
|