Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private lateinit var scenario: FragmentScenario<SearchFragment>
- private val parentActivity = mock<SearchFragment.ParentActivity>()
- @Before
- fun setUp() {
- // Prepare fake data for SearchFragment
- // ...
- // Setup the FragmentScenario and attach any required mock data to it
- scenario = launchFragmentInContainer<SearchFragment>(Bundle.EMPTY, R.style.Theme_AppCompat_Light)
- scenario.onFragment {
- it.setParentActivity(parentActivity)
- }
- }
- @Test
- fun `when loading, progressbar is displayed`() {
- whenSearchReturns(Single.never())
- scenario.onFragment {
- it.performQuery("brexit")
- it.progressBar().shouldBeVisible()
- }
- }
- /////////////////////////////////////////////////////////////////
- private fun whenSearchReturns(singleResult: Single<List<Tag>>) {
- given(searchRequest.execute(any())).willReturn(singleResult)
- }
- private fun SearchFragment.performQuery(query: String) {
- searchView()
- .setQuery(query, true)
- }
- // Or, if you declare these Views in the fragment w/ package-protected level,
- // you can call those fields directly.
- private fun SearchFragment.searchView() =
- view!!.findViewById<SearchView>(R.id.search_card_view_search_view)
- private fun SearchFragment.progressBar() =
- view!!.findViewById<View>(R.id.fragment_search_progress_bar)
- private fun View.shouldBeVisible() {
- visibility shouldEqualTo View.VISIBLE
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement