Fix compilation errors

pull/2064/head
lihenggui 2 years ago
parent a686abc9d5
commit ea32f9f1c4

@ -53,7 +53,6 @@ class ForYouScreenTest {
runBlocking {
hasText(getString(Res.string.feature_foryou_done))
}
}
@Test
@ -228,7 +227,7 @@ class ForYouScreenTest {
}
@Test
fun feed_whenNoInterestsSelectionAndLoading_showsLoadingIndicator() = runTest{
fun feed_whenNoInterestsSelectionAndLoading_showsLoadingIndicator() = runTest {
composeTestRule.setContent {
BoxWithConstraints {
ForYouScreen(

@ -64,7 +64,6 @@ class InterestsScreenTest {
getString(CoreUiR.string.core_ui_interests_card_follow_button_content_desc)
interestsTopicCardUnfollowButton =
getString(CoreUiR.string.core_ui_interests_card_unfollow_button_content_desc)
}
}

@ -35,10 +35,23 @@ import com.google.samples.apps.nowinandroid.core.model.data.UserData
import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource
import com.google.samples.apps.nowinandroid.core.testing.data.followableTopicTestData
import com.google.samples.apps.nowinandroid.core.testing.data.newsResourcesTestData
import com.google.samples.apps.nowinandroid.core.ui.R.string
import kotlinx.coroutines.runBlocking
import nowinandroid.core.ui.generated.resources.core_ui_interests_card_follow_button_content_desc
import nowinandroid.core.ui.generated.resources.core_ui_interests_card_unfollow_button_content_desc
import nowinandroid.feature.search.generated.resources.Res
import nowinandroid.feature.search.generated.resources.feature_search_clear_recent_searches_content_desc
import nowinandroid.feature.search.generated.resources.feature_search_clear_search_text_content_desc
import nowinandroid.feature.search.generated.resources.feature_search_interests
import nowinandroid.feature.search.generated.resources.feature_search_not_ready
import nowinandroid.feature.search.generated.resources.feature_search_to_browse_topics
import nowinandroid.feature.search.generated.resources.feature_search_topics
import nowinandroid.feature.search.generated.resources.feature_search_try_another_search
import nowinandroid.feature.search.generated.resources.feature_search_updates
import org.jetbrains.compose.resources.getString
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import nowinandroid.core.ui.generated.resources.Res as uiR
/**
* UI test for checking the correct behaviour of the Search screen.
@ -68,20 +81,18 @@ class SearchScreenTest {
)
@Before
fun setup() {
composeTestRule.activity.apply {
clearSearchContentDesc = getString(R.string.feature_search_clear_search_text_content_desc)
clearRecentSearchesContentDesc = getString(R.string.feature_search_clear_recent_searches_content_desc)
followButtonContentDesc =
getString(string.core_ui_interests_card_follow_button_content_desc)
unfollowButtonContentDesc =
getString(string.core_ui_interests_card_unfollow_button_content_desc)
topicsString = getString(R.string.feature_search_topics)
updatesString = getString(R.string.feature_search_updates)
tryAnotherSearchString = getString(R.string.feature_search_try_another_search) +
" " + getString(R.string.feature_search_interests) + " " + getString(R.string.feature_search_to_browse_topics)
searchNotReadyString = getString(R.string.feature_search_not_ready)
}
fun setup() = runBlocking {
clearSearchContentDesc = getString(Res.string.feature_search_clear_search_text_content_desc)
clearRecentSearchesContentDesc = getString(Res.string.feature_search_clear_recent_searches_content_desc)
followButtonContentDesc =
getString(uiR.string.core_ui_interests_card_follow_button_content_desc)
unfollowButtonContentDesc =
getString(uiR.string.core_ui_interests_card_unfollow_button_content_desc)
topicsString = getString(Res.string.feature_search_topics)
updatesString = getString(Res.string.feature_search_updates)
tryAnotherSearchString = getString(Res.string.feature_search_try_another_search) +
" " + getString(Res.string.feature_search_interests) + " " + getString(Res.string.feature_search_to_browse_topics)
searchNotReadyString = getString(Res.string.feature_search_not_ready)
}
@Test

@ -84,10 +84,10 @@ import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource
import com.google.samples.apps.nowinandroid.core.ui.DevicePreviews
import com.google.samples.apps.nowinandroid.core.ui.InterestsItem
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success
import com.google.samples.apps.nowinandroid.core.ui.R.string
import com.google.samples.apps.nowinandroid.core.ui.TrackScreenViewEvent
import com.google.samples.apps.nowinandroid.core.ui.collectAsStateWithLifecycle
import com.google.samples.apps.nowinandroid.core.ui.newsFeed
import nowinandroid.core.ui.generated.resources.core_ui_back
import nowinandroid.feature.search.generated.resources.feature_search_clear_recent_searches_content_desc
import nowinandroid.feature.search.generated.resources.feature_search_clear_search_text_content_desc
import nowinandroid.feature.search.generated.resources.feature_search_interests
@ -102,6 +102,7 @@ import nowinandroid.feature.search.generated.resources.feature_search_updates
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.jetbrains.compose.ui.tooling.preview.PreviewParameter
import nowinandroid.core.ui.generated.resources.Res as uiR
import nowinandroid.feature.search.generated.resources.Res as searchR
@Composable
@ -220,7 +221,7 @@ fun EmptySearchResultBody(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(horizontal = 48.dp),
) {
val message = stringResource(id = searchR.string.feature_search_result_not_found, searchQuery)
val message = stringResource(searchR.string.feature_search_result_not_found, searchQuery)
val start = message.indexOf(searchQuery)
Text(
text = AnnotatedString(
@ -237,9 +238,9 @@ fun EmptySearchResultBody(
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 24.dp),
)
val interests = stringResource(id = searchR.string.feature_search_interests)
val interests = stringResource(searchR.string.feature_search_interests)
val tryAnotherSearchString = buildAnnotatedString {
append(stringResource(id = searchR.string.feature_search_try_another_search))
append(stringResource(searchR.string.feature_search_try_another_search))
append(" ")
withStyle(
style = SpanStyle(
@ -251,7 +252,7 @@ fun EmptySearchResultBody(
append(interests)
}
append(" ")
append(stringResource(id = searchR.string.feature_search_to_browse_topics))
append(stringResource(searchR.string.feature_search_to_browse_topics))
}
ClickableText(
text = tryAnotherSearchString,
@ -279,7 +280,7 @@ private fun SearchNotReadyBody() {
modifier = Modifier.padding(horizontal = 48.dp),
) {
Text(
text = stringResource(id = searchR.string.feature_search_not_ready),
text = stringResource(searchR.string.feature_search_not_ready),
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 24.dp),
@ -320,7 +321,7 @@ private fun SearchResultBody(
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append(stringResource(id = searchR.string.feature_search_topics))
append(stringResource(searchR.string.feature_search_topics))
}
},
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
@ -356,7 +357,7 @@ private fun SearchResultBody(
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append(stringResource(id = searchR.string.feature_search_updates))
append(stringResource(searchR.string.feature_search_updates))
}
},
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
@ -408,7 +409,7 @@ private fun RecentSearchesBody(
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append(stringResource(id = searchR.string.feature_search_recent_searches))
append(stringResource(searchR.string.feature_search_recent_searches))
}
},
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
@ -423,7 +424,7 @@ private fun RecentSearchesBody(
Icon(
imageVector = NiaIcons.Close,
contentDescription = stringResource(
id = searchR.string.feature_search_clear_recent_searches_content_desc,
searchR.string.feature_search_clear_recent_searches_content_desc,
),
tint = MaterialTheme.colorScheme.onSurface,
)
@ -461,7 +462,7 @@ private fun SearchToolbar(
Icon(
imageVector = NiaIcons.ArrowBack,
contentDescription = stringResource(
id = string.core_ui_back,
uiR.string.core_ui_back,
),
)
}
@ -497,7 +498,7 @@ private fun SearchTextField(
Icon(
imageVector = NiaIcons.Search,
contentDescription = stringResource(
id = searchR.string.feature_search_title,
searchR.string.feature_search_title,
),
tint = MaterialTheme.colorScheme.onSurface,
)
@ -512,7 +513,7 @@ private fun SearchTextField(
Icon(
imageVector = NiaIcons.Close,
contentDescription = stringResource(
id = searchR.string.feature_search_clear_search_text_content_desc,
searchR.string.feature_search_clear_search_text_content_desc,
),
tint = MaterialTheme.colorScheme.onSurface,
)

@ -18,10 +18,10 @@
package com.google.samples.apps.nowinandroid.feature.search
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.core.ui.PreviewParameterData.newsResources
import com.google.samples.apps.nowinandroid.core.ui.PreviewParameterData.topics
import org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider
/**
* This [PreviewParameterProvider](https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewParameterProvider)

@ -28,7 +28,7 @@ import com.google.samples.apps.nowinandroid.core.data.repository.UserDataReposit
import com.google.samples.apps.nowinandroid.core.domain.GetRecentSearchQueriesUseCase
import com.google.samples.apps.nowinandroid.core.domain.GetSearchContentsUseCase
import com.google.samples.apps.nowinandroid.core.model.data.UserSearchResult
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
@ -37,9 +37,9 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
import me.tatarka.inject.annotations.Inject
@HiltViewModel
@OptIn(ExperimentalCoroutinesApi::class)
class SearchViewModel @Inject constructor(
getSearchContentsUseCase: GetSearchContentsUseCase,
recentSearchQueriesUseCase: GetRecentSearchQueriesUseCase,

@ -20,7 +20,6 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.google.samples.apps.nowinandroid.feature.search.SearchRoute
const val SEARCH_ROUTE = "search_route"
@ -34,10 +33,10 @@ fun NavGraphBuilder.searchScreen(
// TODO: Handle back stack for each top-level destination. At the moment each top-level
// destination may have own search screen's back stack.
composable(route = SEARCH_ROUTE) {
SearchRoute(
onBackClick = onBackClick,
onInterestsClick = onInterestsClick,
onTopicClick = onTopicClick,
)
// SearchRoute(
// onBackClick = onBackClick,
// onInterestsClick = onInterestsClick,
// onTopicClick = onTopicClick,
// )
}
}

Loading…
Cancel
Save