Skip to content

Instantly share code, notes, and snippets.

@merttoptas
Last active March 22, 2023 13:23
Show Gist options
  • Save merttoptas/91b6a8caf880fad03f6845df0cf572d2 to your computer and use it in GitHub Desktop.
Save merttoptas/91b6a8caf880fad03f6845df0cf572d2 to your computer and use it in GitHub Desktop.
@RunWith(AndroidJUnit4::class)
class AppDeepLinkingTest {
@get:Rule
val activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
private lateinit var scenario: ActivityScenario<MainActivity>
@Before
fun setup() {
scenario = activityScenarioRule.scenario
}
@After
fun cleanup() {
scenario.close()
}
@Test
fun deepLinkApplicationTextDashboardDeeplinkHasText() {
// Launch the activity with the deep link
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("example://compose/dashboard/johnDoe")
}
scenario.onActivity { activity ->
activity.startActivity(intent)
}
// Verify that the activity displays the expected text
val value = composeTestRule.onNodeWithTag("dashboardDeeplinkArgument")
value.assertTextEquals("This is Home Screen johnDoe")
for ((key, value) in value.fetchSemanticsNode().config) {
if (key.name == "EditableText") {
assertEquals("This is Home Screen johnDoe", value.toString())
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment