Skip to content

Instantly share code, notes, and snippets.

@emmano
Created December 30, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmano/d50e6a2cfbecf639e4a6aceaf9182806 to your computer and use it in GitHub Desktop.
Save emmano/d50e6a2cfbecf639e4a6aceaf9182806 to your computer and use it in GitHub Desktop.
class TestFragmentTest: RobolectricTest() {
@Test
fun `test adapter dsl`() {
val scenario = launchFragmentInContainer<TestFragment>()
scenario.onFragment {
val recyclerView = it.requireView().findViewById<RecyclerView>(R.id.recycler)
val headerViewHolder =
recyclerView.findViewHolderForLayoutPosition(0) ?: throw IllegalStateException()
val header =
headerViewHolder.itemView.findViewById<TextView>(R.id.header)
assertThat(header.text.toString(), equalTo("Title"))
header.performClick()
val titleText = ShadowToast.getTextOfLatestToast()
assertThat(titleText, equalTo("Title"))
val contentViewHolder =
recyclerView.findViewHolderForLayoutPosition(1) ?: throw IllegalStateException()
contentViewHolder.itemView.performClick()
val rowText = ShadowToast.getTextOfLatestToast()
assertThat(rowText, equalTo("Row Tapped"))
val content =
contentViewHolder.itemView.findViewById<TextView>(R.id.content)
assertThat(content.text.toString(), equalTo("Content"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment