Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. private lateinit var scenario: FragmentScenario<SearchFragment>
  2. private val parentActivity = mock<SearchFragment.ParentActivity>()
  3.  
  4. @Before
  5. fun setUp() {
  6. // Prepare fake data for SearchFragment
  7. // ...
  8.  
  9. // Setup the FragmentScenario and attach any required mock data to it
  10. scenario = launchFragmentInContainer<SearchFragment>(Bundle.EMPTY, R.style.Theme_AppCompat_Light)
  11. scenario.onFragment {
  12. it.setParentActivity(parentActivity)
  13. }
  14. }
  15.  
  16. @Test
  17. fun `when loading, progressbar is displayed`() {
  18. whenSearchReturns(Single.never())
  19.  
  20. scenario.onFragment {
  21. it.performQuery("brexit")
  22.  
  23. it.progressBar().shouldBeVisible()
  24. }
  25. }
  26.  
  27. /////////////////////////////////////////////////////////////////
  28.  
  29. private fun whenSearchReturns(singleResult: Single<List<Tag>>) {
  30. given(searchRequest.execute(any())).willReturn(singleResult)
  31. }
  32.  
  33. private fun SearchFragment.performQuery(query: String) {
  34. searchView()
  35. .setQuery(query, true)
  36. }
  37.  
  38. // Or, if you declare these Views in the fragment w/ package-protected level,
  39. // you can call those fields directly.
  40. private fun SearchFragment.searchView() =
  41. view!!.findViewById<SearchView>(R.id.search_card_view_search_view)
  42.  
  43. private fun SearchFragment.progressBar() =
  44. view!!.findViewById<View>(R.id.fragment_search_progress_bar)
  45.  
  46. private fun View.shouldBeVisible() {
  47. visibility shouldEqualTo View.VISIBLE
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement