• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.airbnb.lottie.samples
2 
3 import android.graphics.Color
4 import android.graphics.drawable.ColorDrawable
5 import androidx.fragment.app.Fragment
6 import androidx.fragment.app.testing.launchFragmentInContainer
7 import androidx.lifecycle.Lifecycle
8 import androidx.test.espresso.Espresso.onView
9 import androidx.test.espresso.assertion.ViewAssertions.matches
10 import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
11 import androidx.test.espresso.matcher.ViewMatchers.withId
12 import androidx.test.ext.junit.runners.AndroidJUnit4
13 import androidx.test.filters.LargeTest
14 import com.airbnb.lottie.LottieAnimationView
15 import com.airbnb.lottie.LottieCompositionFactory
16 import com.airbnb.lottie.LottieDrawable
17 import org.junit.Assert.assertFalse
18 import org.junit.Assert.assertTrue
19 import org.junit.Test
20 import org.junit.runner.RunWith
21 
22 @RunWith(AndroidJUnit4::class)
23 @LargeTest
24 class LottieAnimationViewTest {
25     @Test
26     fun inflateShouldNotCrash() {
27         class TestFragment : Fragment(R.layout.lottie_activity_main)
28         launchFragmentInContainer<TestFragment>()
29         onView(withId(R.id.animation_view)).check(matches(isDisplayed()))
30     }
31 
32     @Test
33     fun testCanSetAnAnimationAndChangeItBack() {
34         class TestFragment : Fragment(R.layout.lottie_activity_main)
35 
36         val scenario = launchFragmentInContainer<TestFragment>()
37         scenario.moveToState(Lifecycle.State.RESUMED)
38         scenario.onFragment { fragment ->
39             val composition = LottieCompositionFactory.fromRawResSync(fragment.requireContext(), R.raw.hamburger_arrow).value!!
40             val view = fragment.requireView().findViewById<LottieAnimationView>(R.id.animation_view)
41             view.setComposition(composition)
42             assertTrue(view.drawable is LottieDrawable)
43             view.setImageDrawable(ColorDrawable(Color.GREEN))
44             assertTrue(view.drawable is ColorDrawable)
45             view.setComposition(composition)
46             assertTrue(view.drawable is LottieDrawable)
47         }
48     }
49 
50     @Test
51     fun testStopsPlayingWhenDrawableSwitched() {
52         class TestFragment : Fragment(R.layout.lottie_activity_main)
53 
54         val scenario = launchFragmentInContainer<TestFragment>()
55         scenario.moveToState(Lifecycle.State.RESUMED)
56         scenario.onFragment { fragment ->
57             val composition = LottieCompositionFactory.fromRawResSync(fragment.requireContext(), R.raw.hamburger_arrow).value!!
58             val view = fragment.requireView().findViewById<LottieAnimationView>(R.id.animation_view)
59             view.setComposition(composition)
60             view.playAnimation()
61             view.setImageDrawable(ColorDrawable(Color.GREEN))
62             assertFalse(view.isAnimating)
63         }
64     }
65 }
66