Remove hardcoded topic names in `NavigationTest.kt`

pull/862/head
Simon Marquis 1 year ago committed by GitHub
parent cd2fbb02b6
commit 250850cf9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,13 +33,17 @@ import androidx.test.espresso.Espresso
import androidx.test.espresso.NoActivityResumedException
import com.google.samples.apps.nowinandroid.MainActivity
import com.google.samples.apps.nowinandroid.R
import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import javax.inject.Inject
import kotlin.properties.ReadOnlyProperty
import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR
import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR
@ -78,6 +82,9 @@ class NavigationTest {
@get:Rule(order = 3)
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Inject
lateinit var datasource: FakeNiaNetworkDataSource
private fun AndroidComposeTestRule<*, *>.stringResource(@StringRes resId: Int) =
ReadOnlyProperty<Any?, String> { _, _ -> activity.getString(resId) }
@ -92,6 +99,9 @@ class NavigationTest {
private val brand by composeTestRule.stringResource(SettingsR.string.brand_android)
private val ok by composeTestRule.stringResource(SettingsR.string.dismiss_dialog_button_text)
@Before
fun setup() = hiltRule.inject()
@Test
fun firstScreen_isForYou() {
composeTestRule.apply {
@ -251,11 +261,11 @@ class NavigationTest {
}
@Test
fun navigationBar_multipleBackStackInterests() {
fun navigationBar_multipleBackStackInterests() = runTest {
suspend fun randomTopicName() = datasource.getTopics(ids = null).random().name
composeTestRule.apply {
onNodeWithText(interests).performClick()
// TODO: Grab string from fake data
onNodeWithText("Android Studio & Tools").performClick()
onNodeWithText(randomTopicName()).performClick()
// Switch tab
onNodeWithText(forYou).performClick()
@ -264,7 +274,7 @@ class NavigationTest {
onNodeWithText(interests).performClick()
// Verify we're not in the list of interests
onNodeWithText("Android Auto").assertDoesNotExist() // TODO: Grab string from fake data
onNodeWithText(randomTopicName()).assertDoesNotExist()
}
}
}

Loading…
Cancel
Save