|
|
@ -16,17 +16,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.ui
|
|
|
|
package com.google.samples.apps.nowinandroid.ui
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.ui.test.assertCountEquals
|
|
|
|
import androidx.compose.ui.test.assertIsOn
|
|
|
|
import androidx.compose.ui.test.assertIsOn
|
|
|
|
import androidx.compose.ui.test.assertIsSelected
|
|
|
|
import androidx.compose.ui.test.assertIsSelected
|
|
|
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
|
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|
|
|
|
|
|
|
import androidx.compose.ui.test.onAllNodesWithText
|
|
|
|
import androidx.compose.ui.test.onNodeWithContentDescription
|
|
|
|
import androidx.compose.ui.test.onNodeWithContentDescription
|
|
|
|
import androidx.compose.ui.test.onNodeWithText
|
|
|
|
import androidx.compose.ui.test.onNodeWithText
|
|
|
|
import androidx.compose.ui.test.performClick
|
|
|
|
import androidx.compose.ui.test.performClick
|
|
|
|
import androidx.test.espresso.Espresso
|
|
|
|
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.feature.bookmarks.R as BookmarksR
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.settings.R as SettingsR
|
|
|
|
import dagger.hilt.android.testing.BindValue
|
|
|
|
import dagger.hilt.android.testing.BindValue
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidRule
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidRule
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidTest
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidTest
|
|
|
@ -67,6 +72,9 @@ class NavigationTest {
|
|
|
|
private lateinit var forYou: String
|
|
|
|
private lateinit var forYou: String
|
|
|
|
private lateinit var interests: String
|
|
|
|
private lateinit var interests: String
|
|
|
|
private lateinit var sampleTopic: String
|
|
|
|
private lateinit var sampleTopic: String
|
|
|
|
|
|
|
|
private lateinit var appName: String
|
|
|
|
|
|
|
|
private lateinit var saved: String
|
|
|
|
|
|
|
|
private lateinit var settings: String
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
@Before
|
|
|
|
fun setup() {
|
|
|
|
fun setup() {
|
|
|
@ -77,6 +85,9 @@ class NavigationTest {
|
|
|
|
forYou = getString(FeatureForyouR.string.for_you)
|
|
|
|
forYou = getString(FeatureForyouR.string.for_you)
|
|
|
|
interests = getString(FeatureInterestsR.string.interests)
|
|
|
|
interests = getString(FeatureInterestsR.string.interests)
|
|
|
|
sampleTopic = "Headlines"
|
|
|
|
sampleTopic = "Headlines"
|
|
|
|
|
|
|
|
appName = getString(R.string.app_name)
|
|
|
|
|
|
|
|
saved = getString(BookmarksR.string.saved)
|
|
|
|
|
|
|
|
settings = getString(SettingsR.string.top_app_bar_action_icon_description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -146,6 +157,38 @@ class NavigationTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun topLevelDestinations_showTopBarWithTitle() {
|
|
|
|
|
|
|
|
composeTestRule.apply {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Verify that the top bar contains the app name on the first screen.
|
|
|
|
|
|
|
|
onNodeWithText(appName).assertExists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Go to the bookmarks tab, verify that the top bar contains the app name.
|
|
|
|
|
|
|
|
onNodeWithText(saved).performClick()
|
|
|
|
|
|
|
|
onNodeWithText(appName).assertExists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Go to the interests tab, verify that the top bar contains "Interests". This means
|
|
|
|
|
|
|
|
// we'll have 2 elements with the text "Interests" on screen. One in the top bar, and
|
|
|
|
|
|
|
|
// one in the bottom navigation.
|
|
|
|
|
|
|
|
onNodeWithText(interests).performClick()
|
|
|
|
|
|
|
|
onAllNodesWithText(interests).assertCountEquals(2)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun topLevelDestinations_showSettingsIcon() {
|
|
|
|
|
|
|
|
composeTestRule.apply {
|
|
|
|
|
|
|
|
onNodeWithContentDescription(settings).assertExists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onNodeWithText(saved).performClick()
|
|
|
|
|
|
|
|
onNodeWithContentDescription(settings).assertExists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onNodeWithText(interests).performClick()
|
|
|
|
|
|
|
|
onNodeWithContentDescription(settings).assertExists()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* There should always be at most one instance of a top-level destination at the same time.
|
|
|
|
* There should always be at most one instance of a top-level destination at the same time.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|