This answer demonstrates how to embed a link within an annotated string and make it clickable. This works great and triggers the on click with the correct URL. However, I can't seem to write a test that clicks the annotated text to open the link. Has anyone had success writing a test like this? My production code is very similar to what is in the answer. Below is my test code:
@Test
fun it_should_open_terms_of_service_link() {
val termsOfServiceText = getString(R.string.settings_terms)
try {
Intents.init()
stubAnyIntent()
composeTestRule.onNode(hasText(termsOfServiceText, substring = true)).performClick()
assertLinkWasOpened(getString(R.string.settings_terms_link))
} finally {
Intents.release()
}
}
It looks like hasText(termsOfServiceText, substring = true)
fetches the entire annotated string node opposed to just the substring, "Terms of Service". Thus, the on click method does get triggered, just not at the correct position in the annotated string. Happy to provide more info if needed. Thanks!