@@ -22,7 +22,9 @@ import androidx.compose.ui.test.assertIsSelected
22
22
import androidx.compose.ui.test.hasTestTag
23
23
import androidx.compose.ui.test.hasText
24
24
import androidx.compose.ui.test.junit4.createAndroidComposeRule
25
+ import androidx.compose.ui.test.onAllNodesWithTag
25
26
import androidx.compose.ui.test.onAllNodesWithText
27
+ import androidx.compose.ui.test.onFirst
26
28
import androidx.compose.ui.test.onNodeWithContentDescription
27
29
import androidx.compose.ui.test.onNodeWithTag
28
30
import androidx.compose.ui.test.onNodeWithText
@@ -32,6 +34,7 @@ import androidx.test.espresso.Espresso
32
34
import androidx.test.espresso.NoActivityResumedException
33
35
import com.google.samples.apps.nowinandroid.MainActivity
34
36
import com.google.samples.apps.nowinandroid.R
37
+ import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
35
38
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
36
39
import com.google.samples.apps.nowinandroid.core.model.data.Topic
37
40
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
@@ -75,6 +78,9 @@ class NavigationTest {
75
78
@Inject
76
79
lateinit var topicsRepository: TopicsRepository
77
80
81
+ @Inject
82
+ lateinit var newsRepository: NewsRepository
83
+
78
84
// The strings used for matching in these tests
79
85
private val navigateUp by composeTestRule.stringResource(FeatureForyouR .string.feature_foryou_navigate_up)
80
86
private val forYou by composeTestRule.stringResource(FeatureForyouR .string.feature_foryou_title)
@@ -271,21 +277,27 @@ class NavigationTest {
271
277
@Test
272
278
fun navigatingToTopicFromForYou_showsTopicDetails () {
273
279
composeTestRule.apply {
274
- // Follow a topic
275
- onNodeWithText(sampleTopic).performClick()
276
-
277
- // Get the topic ID
278
- val topic = runBlocking {
279
- topicsRepository.getTopics().first().filter { it.name == sampleTopic }.first()
280
+ // Get the first news resource
281
+ val newsResource = runBlocking {
282
+ newsRepository.getNewsResources().first().first()
280
283
}
281
284
282
- // Tap the first topic chip
283
- onNodeWithTag(" topicChip:${topic.id} " , useUnmergedTree = true )
284
- .assertExists()
285
- .performClick()
285
+ // Get its first topic and follow it
286
+ val topic = newsResource.topics.first()
287
+ onNodeWithText(topic.name).performClick()
286
288
287
- // TEST FAILING HERE
288
- composeTestRule.waitUntil(timeoutMillis = 3_600_000 , condition = { false })
289
+ // Get the news feed and scroll to the news resource
290
+ // Note: Possible flakiness. If the content of the news resource is long then the topic
291
+ // tag might not be visible meaning it cannot be clicked
292
+ onNodeWithTag(" forYou:feed" )
293
+ .performScrollToNode(
294
+ hasTestTag(" newsResourceCard:${newsResource.id} " ),
295
+ )
296
+
297
+ // Click the first topic tag
298
+ onAllNodesWithTag(" topicTag:${topic.id} " , useUnmergedTree = true )
299
+ .onFirst()
300
+ .performClick()
289
301
290
302
// Verify that we're on the correct topic details screen
291
303
onNodeWithTag(" topic:${topic.id} " ).assertExists()
0 commit comments