parent
b96b3e9e40
commit
04fa1ff2b7
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.navigation
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||||
|
import androidx.navigation3.runtime.EntryProviderBuilder
|
||||||
|
import androidx.navigation3.runtime.NavEntryDecorator
|
||||||
|
import androidx.navigation3.runtime.entryProvider
|
||||||
|
import androidx.navigation3.ui.NavDisplay
|
||||||
|
import com.google.samples.apps.nowinandroid.core.navigation.NiaBackStack
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NiaNavDisplay(
|
||||||
|
niaBackStack: NiaBackStack,
|
||||||
|
entryProviderBuilders: Set<@JvmSuppressWildcards EntryProviderBuilder<Any>.() -> Unit>,
|
||||||
|
) {
|
||||||
|
NavDisplay(
|
||||||
|
backStack = niaBackStack.backStack,
|
||||||
|
onBack = { niaBackStack.removeLast() },
|
||||||
|
entryProvider = entryProvider {
|
||||||
|
entryProviderBuilders.forEach { builder ->
|
||||||
|
builder()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2024 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.ui.interests2pane
|
|
||||||
|
|
||||||
import androidx.lifecycle.SavedStateHandle
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.navigation.toRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.interests.api.navigation.InterestsRoute
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
const val TOPIC_ID_KEY = "selectedTopicId"
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class Interests2PaneViewModel @Inject constructor(
|
|
||||||
private val savedStateHandle: SavedStateHandle,
|
|
||||||
) : ViewModel() {
|
|
||||||
|
|
||||||
val route = savedStateHandle.toRoute<InterestsRoute>()
|
|
||||||
val selectedTopicId: StateFlow<String?> = savedStateHandle.getStateFlow(
|
|
||||||
key = TOPIC_ID_KEY,
|
|
||||||
initialValue = route.initialTopicId,
|
|
||||||
)
|
|
||||||
|
|
||||||
fun onTopicClick(topicId: String?) {
|
|
||||||
savedStateHandle[TOPIC_ID_KEY] = topicId
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2024 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.ui.interests2pane
|
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
|
||||||
import androidx.compose.animation.AnimatedContent
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
|
||||||
import androidx.compose.material3.VerticalDragHandle
|
|
||||||
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
|
|
||||||
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
|
||||||
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
|
||||||
import androidx.compose.material3.adaptive.layout.AnimatedPane
|
|
||||||
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
|
|
||||||
import androidx.compose.material3.adaptive.layout.PaneAdaptedValue
|
|
||||||
import androidx.compose.material3.adaptive.layout.PaneExpansionAnchor
|
|
||||||
import androidx.compose.material3.adaptive.layout.ThreePaneScaffoldDestinationItem
|
|
||||||
import androidx.compose.material3.adaptive.layout.calculatePaneScaffoldDirective
|
|
||||||
import androidx.compose.material3.adaptive.layout.defaultDragHandleSemantics
|
|
||||||
import androidx.compose.material3.adaptive.layout.rememberPaneExpansionState
|
|
||||||
import androidx.compose.material3.adaptive.navigation.BackNavigationBehavior
|
|
||||||
import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneScaffold
|
|
||||||
import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator
|
|
||||||
import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldPredictiveBackHandler
|
|
||||||
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clipToBounds
|
|
||||||
import androidx.compose.ui.layout.layout
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import androidx.navigation.NavGraphBuilder
|
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.interests.api.InterestsRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.interests.api.navigation.InterestsRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.api.TopicDetailPlaceholder
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.api.TopicScreen
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.api.TopicViewModel
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.api.navigation.TopicRoute
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
@Serializable internal object TopicPlaceholderRoute
|
|
||||||
|
|
||||||
fun NavGraphBuilder.interestsListDetailScreen() {
|
|
||||||
composable<InterestsRoute> {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
internal fun InterestsListDetailScreen(
|
|
||||||
viewModel: Interests2PaneViewModel = hiltViewModel(),
|
|
||||||
windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(),
|
|
||||||
) {
|
|
||||||
val selectedTopicId by viewModel.selectedTopicId.collectAsStateWithLifecycle()
|
|
||||||
InterestsListDetailScreen(
|
|
||||||
selectedTopicId = selectedTopicId,
|
|
||||||
onTopicClick = viewModel::onTopicClick,
|
|
||||||
windowAdaptiveInfo = windowAdaptiveInfo,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
|
|
||||||
@Composable
|
|
||||||
internal fun InterestsListDetailScreen(
|
|
||||||
selectedTopicId: String?,
|
|
||||||
onTopicClick: (String) -> Unit,
|
|
||||||
windowAdaptiveInfo: WindowAdaptiveInfo,
|
|
||||||
) {
|
|
||||||
val listDetailNavigator = rememberListDetailPaneScaffoldNavigator(
|
|
||||||
scaffoldDirective = calculatePaneScaffoldDirective(windowAdaptiveInfo),
|
|
||||||
initialDestinationHistory = listOfNotNull(
|
|
||||||
ThreePaneScaffoldDestinationItem(ListDetailPaneScaffoldRole.List),
|
|
||||||
ThreePaneScaffoldDestinationItem<Nothing>(ListDetailPaneScaffoldRole.Detail).takeIf {
|
|
||||||
selectedTopicId != null
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
val paneExpansionState = rememberPaneExpansionState(
|
|
||||||
anchors = listOf(
|
|
||||||
PaneExpansionAnchor.Proportion(0f),
|
|
||||||
PaneExpansionAnchor.Proportion(0.5f),
|
|
||||||
PaneExpansionAnchor.Proportion(1f),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
ThreePaneScaffoldPredictiveBackHandler(
|
|
||||||
listDetailNavigator,
|
|
||||||
BackNavigationBehavior.PopUntilScaffoldValueChange,
|
|
||||||
)
|
|
||||||
BackHandler(
|
|
||||||
paneExpansionState.currentAnchor == PaneExpansionAnchor.Proportion(0f) &&
|
|
||||||
listDetailNavigator.isListPaneVisible() &&
|
|
||||||
listDetailNavigator.isDetailPaneVisible(),
|
|
||||||
) {
|
|
||||||
coroutineScope.launch {
|
|
||||||
paneExpansionState.animateTo(PaneExpansionAnchor.Proportion(1f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var topicRoute by remember {
|
|
||||||
val route = selectedTopicId?.let { TopicRoute(id = it) } ?: TopicPlaceholderRoute
|
|
||||||
mutableStateOf(route)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onTopicClickShowDetailPane(topicId: String) {
|
|
||||||
onTopicClick(topicId)
|
|
||||||
topicRoute = TopicRoute(id = topicId)
|
|
||||||
coroutineScope.launch {
|
|
||||||
listDetailNavigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
|
|
||||||
}
|
|
||||||
if (paneExpansionState.currentAnchor == PaneExpansionAnchor.Proportion(1f)) {
|
|
||||||
coroutineScope.launch {
|
|
||||||
paneExpansionState.animateTo(PaneExpansionAnchor.Proportion(0f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val mutableInteractionSource = remember { MutableInteractionSource() }
|
|
||||||
val minPaneWidth = 300.dp
|
|
||||||
|
|
||||||
NavigableListDetailPaneScaffold(
|
|
||||||
navigator = listDetailNavigator,
|
|
||||||
listPane = {
|
|
||||||
AnimatedPane {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.clipToBounds()
|
|
||||||
.layout { measurable, constraints ->
|
|
||||||
val width = max(minPaneWidth.roundToPx(), constraints.maxWidth)
|
|
||||||
val placeable = measurable.measure(
|
|
||||||
constraints.copy(
|
|
||||||
minWidth = minPaneWidth.roundToPx(),
|
|
||||||
maxWidth = width,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
layout(constraints.maxWidth, placeable.height) {
|
|
||||||
placeable.placeRelative(
|
|
||||||
x = 0,
|
|
||||||
y = 0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
InterestsRoute(
|
|
||||||
onTopicClick = ::onTopicClickShowDetailPane,
|
|
||||||
shouldHighlightSelectedTopic = listDetailNavigator.isDetailPaneVisible(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
detailPane = {
|
|
||||||
AnimatedPane {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.clipToBounds()
|
|
||||||
.layout { measurable, constraints ->
|
|
||||||
val width = max(minPaneWidth.roundToPx(), constraints.maxWidth)
|
|
||||||
val placeable = measurable.measure(
|
|
||||||
constraints.copy(
|
|
||||||
minWidth = minPaneWidth.roundToPx(),
|
|
||||||
maxWidth = width,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
layout(constraints.maxWidth, placeable.height) {
|
|
||||||
placeable.placeRelative(
|
|
||||||
x = constraints.maxWidth -
|
|
||||||
max(constraints.maxWidth, placeable.width),
|
|
||||||
y = 0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
AnimatedContent(topicRoute) { route ->
|
|
||||||
when (route) {
|
|
||||||
is TopicRoute -> {
|
|
||||||
TopicScreen(
|
|
||||||
showBackButton = !listDetailNavigator.isListPaneVisible(),
|
|
||||||
onBackClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
listDetailNavigator.navigateBack()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onTopicClick = ::onTopicClickShowDetailPane,
|
|
||||||
viewModel = hiltViewModel<TopicViewModel, TopicViewModel.Factory>(
|
|
||||||
key = route.id,
|
|
||||||
) { factory ->
|
|
||||||
factory.create(route.id)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
is TopicPlaceholderRoute -> {
|
|
||||||
TopicDetailPlaceholder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
paneExpansionState = paneExpansionState,
|
|
||||||
paneExpansionDragHandle = {
|
|
||||||
VerticalDragHandle(
|
|
||||||
modifier = Modifier.paneExpansionDraggable(
|
|
||||||
state = paneExpansionState,
|
|
||||||
minTouchTargetSize = LocalMinimumInteractiveComponentSize.current,
|
|
||||||
interactionSource = mutableInteractionSource,
|
|
||||||
semanticsProperties = paneExpansionState.defaultDragHandleSemantics(),
|
|
||||||
),
|
|
||||||
interactionSource = mutableInteractionSource,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
|
|
||||||
private fun <T> ThreePaneScaffoldNavigator<T>.isListPaneVisible(): Boolean =
|
|
||||||
scaffoldValue[ListDetailPaneScaffoldRole.List] == PaneAdaptedValue.Expanded
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
|
|
||||||
private fun <T> ThreePaneScaffoldNavigator<T>.isDetailPaneVisible(): Boolean =
|
|
||||||
scaffoldValue[ListDetailPaneScaffoldRole.Detail] == PaneAdaptedValue.Expanded
|
|
@ -1,204 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2024 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.ui
|
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.compose.ui.test.assertIsDisplayed
|
|
||||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
|
||||||
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
|
|
||||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
||||||
import androidx.compose.ui.test.onNodeWithTag
|
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
|
||||||
import androidx.compose.ui.test.performClick
|
|
||||||
import androidx.test.espresso.Espresso
|
|
||||||
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
|
|
||||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
|
||||||
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
||||||
import com.google.samples.apps.nowinandroid.ui.interests2pane.InterestsListDetailScreen
|
|
||||||
import com.google.samples.apps.nowinandroid.uitesthiltmanifest.HiltComponentActivity
|
|
||||||
import dagger.hilt.android.testing.HiltAndroidRule
|
|
||||||
import dagger.hilt.android.testing.HiltAndroidTest
|
|
||||||
import dagger.hilt.android.testing.HiltTestApplication
|
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
|
||||||
import org.robolectric.annotation.Config
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.properties.ReadOnlyProperty
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.api.R as FeatureTopicR
|
|
||||||
|
|
||||||
private const val EXPANDED_WIDTH = "w1200dp-h840dp"
|
|
||||||
private const val COMPACT_WIDTH = "w412dp-h915dp"
|
|
||||||
|
|
||||||
@HiltAndroidTest
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
|
||||||
@Config(application = HiltTestApplication::class)
|
|
||||||
class InterestsListDetailScreenTest {
|
|
||||||
|
|
||||||
@get:Rule(order = 0)
|
|
||||||
val hiltRule = HiltAndroidRule(this)
|
|
||||||
|
|
||||||
@get:Rule(order = 1)
|
|
||||||
val composeTestRule = createAndroidComposeRule<HiltComponentActivity>()
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var topicsRepository: TopicsRepository
|
|
||||||
|
|
||||||
/** Convenience function for getting all topics during tests, */
|
|
||||||
private fun getTopics(): List<Topic> = runBlocking {
|
|
||||||
topicsRepository.getTopics().first().sortedBy { it.name }
|
|
||||||
}
|
|
||||||
|
|
||||||
// The strings used for matching in these tests.
|
|
||||||
private val placeholderText by composeTestRule.stringResource(FeatureTopicR.string.feature_topic_select_an_interest)
|
|
||||||
private val listPaneTag = "interests:topics"
|
|
||||||
|
|
||||||
private val Topic.testTag
|
|
||||||
get() = "topic:${this.id}"
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setup() {
|
|
||||||
hiltRule.inject()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = EXPANDED_WIDTH)
|
|
||||||
fun expandedWidth_initialState_showsTwoPanesWithPlaceholder() {
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onNodeWithTag(listPaneTag).assertIsDisplayed()
|
|
||||||
onNodeWithText(placeholderText).assertIsDisplayed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = COMPACT_WIDTH)
|
|
||||||
fun compactWidth_initialState_showsListPane() {
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onNodeWithTag(listPaneTag).assertIsDisplayed()
|
|
||||||
onNodeWithText(placeholderText).assertIsNotDisplayed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = EXPANDED_WIDTH)
|
|
||||||
fun expandedWidth_topicSelected_updatesDetailPane() {
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstTopic = getTopics().first()
|
|
||||||
onNodeWithText(firstTopic.name).performClick()
|
|
||||||
|
|
||||||
onNodeWithTag(listPaneTag).assertIsDisplayed()
|
|
||||||
onNodeWithText(placeholderText).assertIsNotDisplayed()
|
|
||||||
onNodeWithTag(firstTopic.testTag).assertIsDisplayed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = COMPACT_WIDTH)
|
|
||||||
fun compactWidth_topicSelected_showsTopicDetailPane() {
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstTopic = getTopics().first()
|
|
||||||
onNodeWithText(firstTopic.name).performClick()
|
|
||||||
|
|
||||||
onNodeWithTag(listPaneTag).assertIsNotDisplayed()
|
|
||||||
onNodeWithText(placeholderText).assertIsNotDisplayed()
|
|
||||||
onNodeWithTag(firstTopic.testTag).assertIsDisplayed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = EXPANDED_WIDTH)
|
|
||||||
fun expandedWidth_backPressFromTopicDetail_leavesInterests() {
|
|
||||||
var unhandledBackPress = false
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
// Back press should not be handled by the two pane layout, and thus
|
|
||||||
// "fall through" to this BackHandler.
|
|
||||||
BackHandler {
|
|
||||||
unhandledBackPress = true
|
|
||||||
}
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstTopic = getTopics().first()
|
|
||||||
onNodeWithText(firstTopic.name).performClick()
|
|
||||||
|
|
||||||
waitForIdle()
|
|
||||||
Espresso.pressBack()
|
|
||||||
|
|
||||||
assertTrue(unhandledBackPress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(qualifiers = COMPACT_WIDTH)
|
|
||||||
fun compactWidth_backPressFromTopicDetail_showsListPane() {
|
|
||||||
composeTestRule.apply {
|
|
||||||
setContent {
|
|
||||||
NiaTheme {
|
|
||||||
InterestsListDetailScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstTopic = getTopics().first()
|
|
||||||
onNodeWithText(firstTopic.name).performClick()
|
|
||||||
|
|
||||||
waitForIdle()
|
|
||||||
Espresso.pressBack()
|
|
||||||
|
|
||||||
onNodeWithTag(listPaneTag).assertIsDisplayed()
|
|
||||||
onNodeWithText(placeholderText).assertIsNotDisplayed()
|
|
||||||
onNodeWithTag(firstTopic.testTag).assertIsNotDisplayed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun AndroidComposeTestRule<*, *>.stringResource(
|
|
||||||
@StringRes resId: Int,
|
|
||||||
): ReadOnlyProperty<Any, String> =
|
|
||||||
ReadOnlyProperty { _, _ -> activity.getString(resId) }
|
|
@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2025 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
sdk = 35
|
Loading…
Reference in new issue