Added second draft of tests

pull/507/head
magicalmeghan 2 years ago
parent 9a900f9900
commit 8089866079

@ -145,17 +145,72 @@ class GetUserNewsResourcesUseCaseTest {
) )
} }
//verify that news resources contain the correct FollowedTopics //whenTopicFollowed_UserNewsResources
@Test @Test
fun newsResourcesContainCorrectFollowedTopics() = runTest { fun checkNewsResourcesContainCorrectFollowedTopics() = runTest {
assertEquals(
sampleNewsResources[0].topics, listOf(sampleTopic1) // Obtain the saveable news resources stream.
) val saveableNewsResources = useCase()
assertEquals(
sampleNewsResources[1].topics, listOf(sampleTopic1, sampleTopic2) // 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( 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()
) )
} }
} }

@ -17,6 +17,7 @@
package com.google.samples.apps.nowinandroid.core.ui package com.google.samples.apps.nowinandroid.core.ui
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onNodeWithText
@ -76,19 +77,16 @@ class NewsResourceCardTest {
.assertIsDisplayed() .assertIsDisplayed()
} }
// Test that chip color is different if topic is followed
@Test @Test
fun testChipColor() { fun testTopicsChipColorBackground_matchesFollowedState() {
val newsWithUnknownResourceType = previewUserNewsResources[1] val followableTopics = previewUserNewsResources[1].topics
composeTestRule.setContent { composeTestRule.setContent {
NewsResourceTopics(topics = newsWithUnknownResourceType.topics) NewsResourceTopics(topics = followableTopics)
} }
composeTestRule composeTestRule
.onNodeWithText("UI") .onNodeWithText(followableTopics[1].topic.name)
//figure out how to get the color of the chip and compare it to .assertContentDescriptionEquals("UI is followed")
// MaterialTheme.colorScheme.primaryContainer
} }
} }

@ -46,12 +46,12 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage 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.NiaIconToggleButton
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopicTag import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopicTag
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons 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.domain.model.previewUserNewsResources
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType 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.Instant
import kotlinx.datetime.toJavaInstant 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 * [NewsResource] card used on the following screens: For You, Saved
@ -249,7 +250,15 @@ fun NewsResourceTopics(
onFollowClick = { }, // ToDo onFollowClick = { }, // ToDo
onUnfollowClick = { }, // ToDo onUnfollowClick = { }, // ToDo
onBrowseClick = { }, // 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
})
}
) )
} }
} }

Loading…
Cancel
Save