Skip to content

Commit 8d57c33

Browse files
committed
your new message
1 parent 7d45eae commit 8d57c33

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

  • feature/topic
    • api/src/main/res/values
    • impl/src
      • androidTest/kotlin/com/google/samples/apps/nowinandroid/feature/topic/impl
      • main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/impl

feature/topic/api/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
-->
1717
<resources>
1818
<string name="feature_topic_api_loading">Loading topic</string>
19+
<string name="feature_topic_api_error_header">Couldn\'t load topic</string>
1920
</resources>

feature/topic/impl/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/feature/topic/impl/TopicScreenTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ class TopicScreenTest {
4242
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
4343

4444
private lateinit var topicLoading: String
45+
private lateinit var topicErrorHeader: String
4546

4647
@Before
4748
fun setup() {
4849
composeTestRule.activity.apply {
4950
topicLoading = getString(R.string.feature_topic_api_loading)
51+
topicErrorHeader = getString(R.string.feature_topic_api_error_header)
5052
}
5153
}
5254

@@ -97,6 +99,26 @@ class TopicScreenTest {
9799
.assertExists()
98100
}
99101

102+
@Test
103+
fun errorMessage_whenTopicIsError_isShown() {
104+
composeTestRule.setContent {
105+
TopicScreen(
106+
topicUiState = TopicUiState.Error,
107+
newsUiState = NewsUiState.Loading,
108+
showBackButton = true,
109+
onBackClick = {},
110+
onFollowClick = {},
111+
onTopicClick = {},
112+
onBookmarkChanged = { _, _ -> },
113+
onNewsResourceViewed = {},
114+
)
115+
}
116+
117+
composeTestRule
118+
.onNodeWithText(topicErrorHeader)
119+
.assertExists()
120+
}
121+
100122
@Test
101123
fun news_whenTopicIsLoading_isNotShown() {
102124
composeTestRule.setContent {

feature/topic/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/impl/TopicScreen.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ internal fun TopicScreen(
129129
)
130130
}
131131

132-
TopicUiState.Error -> TODO()
132+
TopicUiState.Error -> item {
133+
TopicErrorBody()
134+
}
133135
is TopicUiState.Success -> {
134136
item {
135137
TopicToolbar(
@@ -177,7 +179,7 @@ private fun topicItemsSize(
177179
topicUiState: TopicUiState,
178180
newsUiState: NewsUiState,
179181
) = when (topicUiState) {
180-
TopicUiState.Error -> 0 // Nothing
182+
TopicUiState.Error -> 1 // Error message
181183
TopicUiState.Loading -> 1 // Loading bar
182184
is TopicUiState.Success -> when (newsUiState) {
183185
NewsUiState.Error -> 0 // Nothing
@@ -203,6 +205,22 @@ private fun LazyListScope.topicBody(
203205
userNewsResourceCards(news, onBookmarkChanged, onNewsResourceViewed, onTopicClick)
204206
}
205207

208+
@Composable
209+
private fun TopicErrorBody() {
210+
Column(
211+
horizontalAlignment = Alignment.CenterHorizontally,
212+
modifier = Modifier
213+
.fillMaxWidth()
214+
.padding(horizontal = 48.dp),
215+
) {
216+
Text(
217+
text = stringResource(id = TopicR.string.feature_topic_api_error_header),
218+
style = MaterialTheme.typography.bodyLarge,
219+
modifier = Modifier.padding(vertical = 24.dp),
220+
)
221+
}
222+
}
223+
206224
@Composable
207225
private fun TopicHeader(name: String, description: String, imageUrl: String) {
208226
Column(

0 commit comments

Comments
 (0)