Skip to content

Commit

Permalink
Fix FragmentVisibilityTests (#1979)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeal committed Jan 8, 2022
1 parent e73ad50 commit 3ee8813
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onIdle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions
Expand Down Expand Up @@ -102,23 +103,21 @@ class FragmentVisibilityTests {
@Test
fun testDoesntStopOnPause() {
class TestFragment : Fragment() {
lateinit var animationView: LottieAnimationView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.auto_play, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
animationView = view.findViewById(R.id.animation_view)
IdlingRegistry.getInstance().register(LottieIdlingResource(animationView))
IdlingRegistry.getInstance().register(LottieIdlingResource(view.findViewById(R.id.animation_view)))
AlertDialog.Builder(requireContext()).setTitle("This is a dialog").show()
}
}

val scenario = launchFragmentInContainer<TestFragment>(themeResId = R.style.Theme_AppCompat)
scenario.moveToState(Lifecycle.State.RESUMED)
onIdle()
scenario.onFragment { fragment ->
val animationView = fragment.requireView().findViewById<LottieAnimationView>(R.id.animation_view)
// Wait for the animation view.
onView(withId(R.id.animation_view))
// We have to use a property reference because the Fragment isn't resumed.
assertTrue(fragment.animationView.isAnimating)
}
Expand Down

0 comments on commit 3ee8813

Please sign in to comment.