Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions feature/topic/api/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
-->
<resources>
<string name="feature_topic_api_loading">Loading topic</string>
<string name="feature_topic_api_error">Unable to load topic</string>
<string name="feature_topic_api_news_error">Unable to load news</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ class TopicScreenTest {
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

private lateinit var topicLoading: String
private lateinit var topicError: String

@Before
fun setup() {
composeTestRule.activity.apply {
topicLoading = getString(R.string.feature_topic_api_loading)
topicError = getString(R.string.feature_topic_api_error)
}
}

Expand All @@ -70,6 +72,26 @@ class TopicScreenTest {
.assertExists()
}

@Test
fun topicError_whenTopicIsError_isShown() {
composeTestRule.setContent {
TopicScreen(
topicUiState = TopicUiState.Error,
newsUiState = NewsUiState.Loading,
showBackButton = true,
onBackClick = {},
onFollowClick = {},
onTopicClick = {},
onBookmarkChanged = { _, _ -> },
onNewsResourceViewed = {},
)
}

composeTestRule
.onNodeWithText(topicError)
.assertExists()
}

@Test
fun topicTitle_whenTopicIsSuccess_isShown() {
val testTopic = followableTopicTestData.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,17 @@ internal fun TopicScreen(
)
}

TopicUiState.Error -> TODO()
TopicUiState.Error -> {
item {
TopicErrorToolbar(
showBackButton = showBackButton,
onBackClick = onBackClick,
)
}
item {
TopicErrorState()
}
}
is TopicUiState.Success -> {
item {
TopicToolbar(
Expand Down Expand Up @@ -177,7 +187,7 @@ private fun topicItemsSize(
topicUiState: TopicUiState,
newsUiState: NewsUiState,
) = when (topicUiState) {
TopicUiState.Error -> 0 // Nothing
TopicUiState.Error -> 2 // Toolbar and error message
Comment thread
saadkhalidkhan marked this conversation as resolved.
TopicUiState.Loading -> 1 // Loading bar
is TopicUiState.Success -> when (newsUiState) {
NewsUiState.Error -> 0 // Nothing
Expand Down Expand Up @@ -250,7 +260,11 @@ private fun LazyListScope.userNewsResourceCards(
}

else -> item {
Text("Error") // TODO
Text(
text = stringResource(id = TopicR.string.feature_topic_api_news_error),
modifier = Modifier.padding(24.dp),
style = MaterialTheme.typography.bodyLarge,
)
}
}
}
Expand All @@ -273,6 +287,44 @@ private fun TopicBodyPreview() {
}
}

@Composable
private fun TopicErrorState(modifier: Modifier = Modifier) {
Text(
text = stringResource(id = TopicR.string.feature_topic_api_error),
modifier = modifier
.fillMaxWidth()
.padding(24.dp)
.testTag("topic:error"),
style = MaterialTheme.typography.bodyLarge,
)
}

@Composable
private fun TopicErrorToolbar(
showBackButton: Boolean,
onBackClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.fillMaxWidth()
.padding(bottom = 32.dp),
) {
if (showBackButton) {
IconButton(onClick = onBackClick) {
Icon(
imageVector = NiaIcons.ArrowBack,
contentDescription = stringResource(
id = UiR.string.core_ui_back,
),
)
}
}
}
}

@Composable
private fun TopicToolbar(
uiState: FollowableTopic,
Expand Down