Skip to content

Instantly share code, notes, and snippets.

@adavis
Last active Sep 17, 2021
Embed
What would you like to do?
Instrumentation tests for Jetpack Compose screen using Intents for navigation
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.meetup.organizer.home.HomeFragment"
android:label="HomeFragment">
<action
android:id="@+id/action_homeFragment_to_nonOrganizerFragment"
app:destination="@id/nonOrganizerFragment" />
</fragment>
<fragment
android:id="@+id/nonOrganizerFragment"
android:name="com.meetup.organizer.auth.NonOrganizerFragment"
android:label="NonOrganizerFragment" />
</navigation>
@ExperimentalAnimationApi
@RunWith(AndroidJUnit4::class)
class NonOrganizerTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Before
fun goToNonOrganizerFragment() {
composeTestRule.activityRule.scenario.onActivity {
findNavController(it, R.id.nav_host_fragment).navigate(R.id.nonOrganizerFragment)
}
Intents.init()
}
@After
fun tearDown() {
Intents.release()
}
@Test
fun shouldDisplayStaticContent() {
listOf(
NON_ORGANIZER_MAIN_IMAGE,
NON_ORGANIZER_MAIN_TEXT,
NON_ORGANIZER_CONTACT_US,
NON_ORGANIZER_MEMBER_APP
).onEach {
composeTestRule.onNodeWithTag(it)
.assertIsDisplayed()
}
}
@Test
fun shouldGoToWeb_whenContactUsClicked() {
composeTestRule.onNodeWithTag(NON_ORGANIZER_CONTACT_US).performClick()
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://help.meetup.com")
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment