|
|
@ -22,7 +22,9 @@ import androidx.compose.ui.test.assertIsSelected
|
|
|
|
import androidx.compose.ui.test.hasTestTag
|
|
|
|
import androidx.compose.ui.test.hasTestTag
|
|
|
|
import androidx.compose.ui.test.hasText
|
|
|
|
import androidx.compose.ui.test.hasText
|
|
|
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
|
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
|
|
|
|
|
|
import androidx.compose.ui.test.onAllNodesWithTag
|
|
|
|
import androidx.compose.ui.test.onAllNodesWithText
|
|
|
|
import androidx.compose.ui.test.onAllNodesWithText
|
|
|
|
|
|
|
|
import androidx.compose.ui.test.onFirst
|
|
|
|
import androidx.compose.ui.test.onNodeWithContentDescription
|
|
|
|
import androidx.compose.ui.test.onNodeWithContentDescription
|
|
|
|
import androidx.compose.ui.test.onNodeWithTag
|
|
|
|
import androidx.compose.ui.test.onNodeWithTag
|
|
|
|
import androidx.compose.ui.test.onNodeWithText
|
|
|
|
import androidx.compose.ui.test.onNodeWithText
|
|
|
@ -32,6 +34,7 @@ import androidx.test.espresso.Espresso
|
|
|
|
import androidx.test.espresso.NoActivityResumedException
|
|
|
|
import androidx.test.espresso.NoActivityResumedException
|
|
|
|
import com.google.samples.apps.nowinandroid.MainActivity
|
|
|
|
import com.google.samples.apps.nowinandroid.MainActivity
|
|
|
|
import com.google.samples.apps.nowinandroid.R
|
|
|
|
import com.google.samples.apps.nowinandroid.R
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
|
|
|
|
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
|
|
|
@ -75,6 +78,9 @@ class NavigationTest {
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
lateinit var topicsRepository: TopicsRepository
|
|
|
|
lateinit var topicsRepository: TopicsRepository
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
|
|
|
lateinit var newsRepository: NewsRepository
|
|
|
|
|
|
|
|
|
|
|
|
// The strings used for matching in these tests
|
|
|
|
// The strings used for matching in these tests
|
|
|
|
private val navigateUp by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_navigate_up)
|
|
|
|
private val navigateUp by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_navigate_up)
|
|
|
|
private val forYou by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_title)
|
|
|
|
private val forYou by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_title)
|
|
|
@ -271,21 +277,27 @@ class NavigationTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun navigatingToTopicFromForYou_showsTopicDetails() {
|
|
|
|
fun navigatingToTopicFromForYou_showsTopicDetails() {
|
|
|
|
composeTestRule.apply {
|
|
|
|
composeTestRule.apply {
|
|
|
|
// Follow a topic
|
|
|
|
// Get the first news resource
|
|
|
|
onNodeWithText(sampleTopic).performClick()
|
|
|
|
val newsResource = runBlocking {
|
|
|
|
|
|
|
|
newsRepository.getNewsResources().first().first()
|
|
|
|
// Get the topic ID
|
|
|
|
|
|
|
|
val topic = runBlocking {
|
|
|
|
|
|
|
|
topicsRepository.getTopics().first().filter { it.name == sampleTopic }.first()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Tap the first topic chip
|
|
|
|
// Get its first topic and follow it
|
|
|
|
onNodeWithTag("topicChip:${topic.id}", useUnmergedTree = true)
|
|
|
|
val topic = newsResource.topics.first()
|
|
|
|
.assertExists()
|
|
|
|
onNodeWithText(topic.name).performClick()
|
|
|
|
.performClick()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TEST FAILING HERE
|
|
|
|
// Get the news feed and scroll to the news resource
|
|
|
|
composeTestRule.waitUntil(timeoutMillis = 3_600_000, condition = { false })
|
|
|
|
// Note: Possible flakiness. If the content of the news resource is long then the topic
|
|
|
|
|
|
|
|
// tag might not be visible meaning it cannot be clicked
|
|
|
|
|
|
|
|
onNodeWithTag("forYou:feed")
|
|
|
|
|
|
|
|
.performScrollToNode(
|
|
|
|
|
|
|
|
hasTestTag("newsResourceCard:${newsResource.id}"),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Click the first topic tag
|
|
|
|
|
|
|
|
onAllNodesWithTag("topicTag:${topic.id}", useUnmergedTree = true)
|
|
|
|
|
|
|
|
.onFirst()
|
|
|
|
|
|
|
|
.performClick()
|
|
|
|
|
|
|
|
|
|
|
|
// Verify that we're on the correct topic details screen
|
|
|
|
// Verify that we're on the correct topic details screen
|
|
|
|
onNodeWithTag("topic:${topic.id}").assertExists()
|
|
|
|
onNodeWithTag("topic:${topic.id}").assertExists()
|
|
|
|