diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt index 5ba0d66cb..5fc822124 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt @@ -145,17 +145,72 @@ class GetUserNewsResourcesUseCaseTest { ) } - //verify that news resources contain the correct FollowedTopics + //whenTopicFollowed_UserNewsResources @Test - fun newsResourcesContainCorrectFollowedTopics() = runTest { - assertEquals( - sampleNewsResources[0].topics, listOf(sampleTopic1) - ) - assertEquals( - sampleNewsResources[1].topics, listOf(sampleTopic1, sampleTopic2) - ) + fun checkNewsResourcesContainCorrectFollowedTopics() = runTest { + + // Obtain the saveable news resources stream. + val saveableNewsResources = useCase() + + // Send some news resources. + newsRepository.sendNewsResources(sampleNewsResources) + + // Set a followed topic for the user. + userDataRepository.setFollowedTopicIds(setOf(sampleTopic1.id)) + + // Check that the followed topic is marked followed in the UserNewsResources assertEquals( - sampleNewsResources[2].topics, listOf(sampleTopic2) + listOf( + UserNewsResource( + sampleNewsResources[0].id, + sampleNewsResources[0].title, + sampleNewsResources[0].content, + sampleNewsResources[0].url, + sampleNewsResources[0].headerImageUrl, + sampleNewsResources[0].publishDate, + sampleNewsResources[0].type, + sampleNewsResources[0].topics.map { topic -> + FollowableTopic( + topic = topic, + isFollowed = topic.id == sampleTopic1.id + ) + }, + false + ), + UserNewsResource( + sampleNewsResources[1].id, + sampleNewsResources[1].title, + sampleNewsResources[1].content, + sampleNewsResources[1].url, + sampleNewsResources[1].headerImageUrl, + sampleNewsResources[1].publishDate, + sampleNewsResources[1].type, + sampleNewsResources[1].topics.map { topic -> + FollowableTopic( + topic = topic, + isFollowed = topic.id == sampleTopic1.id + ) + }, + false + ), + UserNewsResource( + sampleNewsResources[2].id, + sampleNewsResources[2].title, + sampleNewsResources[2].content, + sampleNewsResources[2].url, + sampleNewsResources[2].headerImageUrl, + sampleNewsResources[2].publishDate, + sampleNewsResources[2].type, + sampleNewsResources[2].topics.map { topic -> + FollowableTopic( + topic = topic, + isFollowed = topic.id == sampleTopic1.id + ) + }, + false + ), + ), + saveableNewsResources.first() ) } } diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 748a8d1a5..3a8ce415d 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -17,6 +17,7 @@ package com.google.samples.apps.nowinandroid.core.ui import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertContentDescriptionEquals import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithText @@ -76,19 +77,16 @@ class NewsResourceCardTest { .assertIsDisplayed() } - // Test that chip color is different if topic is followed @Test - fun testChipColor() { - val newsWithUnknownResourceType = previewUserNewsResources[1] + fun testTopicsChipColorBackground_matchesFollowedState() { + val followableTopics = previewUserNewsResources[1].topics composeTestRule.setContent { - NewsResourceTopics(topics = newsWithUnknownResourceType.topics) + NewsResourceTopics(topics = followableTopics) } composeTestRule - .onNodeWithText("UI") - //figure out how to get the color of the chip and compare it to - // MaterialTheme.colorScheme.primaryContainer - + .onNodeWithText(followableTopics[1].topic.name) + .assertContentDescriptionEquals("UI is followed") } -} +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 9f9129b49..c13d3f986 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -46,12 +46,12 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.AsyncImage -import com.google.samples.apps.nowinandroid.core.designsystem.R as DesignsystemR import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaIconToggleButton import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopicTag import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons @@ -61,11 +61,12 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource import com.google.samples.apps.nowinandroid.core.domain.model.previewUserNewsResources import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import java.time.ZoneId -import java.time.format.DateTimeFormatter -import java.util.Locale import kotlinx.datetime.Instant import kotlinx.datetime.toJavaInstant +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.util.* +import com.google.samples.apps.nowinandroid.core.designsystem.R as DesignsystemR /** * [NewsResource] card used on the following screens: For You, Saved @@ -249,7 +250,15 @@ fun NewsResourceTopics( onFollowClick = { }, // ToDo onUnfollowClick = { }, // ToDo onBrowseClick = { }, // ToDo - text = { Text(text = followableTopic.topic.name.uppercase(Locale.getDefault())) } + text = { + Text(text = followableTopic.topic.name.uppercase(Locale.getDefault()), + modifier = Modifier.semantics { + contentDescription = followableTopic.topic.name + + if (followableTopic.isFollowed) " is followed" + else " is not followed" + //make sure this is the right place to add this - remove hardcoded strings + }) + } ) } }