forked from wix/react-native-navigation
/
BaseViewAnimatorTest.kt
109 lines (89 loc) · 3.31 KB
/
BaseViewAnimatorTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.reactnativenavigation.views.animations
import android.animation.Animator
import android.view.View
import com.reactnativenavigation.BaseTest
import com.reactnativenavigation.options.AnimationOptions
import org.assertj.core.api.Java6Assertions.assertThat
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
class BaseViewAnimatorTest : BaseTest() {
private lateinit var uut: BaseViewAnimator<View>
private lateinit var view: View
private lateinit var defaultAnimatorCreator: ViewAnimatorCreator
private val defaultShowAnimator: Animator
get() = defaultAnimatorCreator.getShowAnimator(view, BaseViewAnimator.HideDirection.Up, 0f)
private val defaultHideAnimator: Animator
get() = defaultAnimatorCreator.getHideAnimator(view, BaseViewAnimator.HideDirection.Up, 0f)
override fun beforeEach() {
view = View(newActivity())
defaultAnimatorCreator = DefaultViewAnimatorCreatorFake()
uut = BaseViewAnimator(
hideDirection = BaseViewAnimator.HideDirection.Up,
view = view,
defaultAnimatorCreator = defaultAnimatorCreator
)
}
@Test
fun show() {
view.visibility = View.GONE
assertNotAnimating()
uut.show()
assertAnimatingShow()
}
@Test
fun show_doesNothingIsAlreadyAnimatingShow() {
view.visibility = View.GONE
uut.show()
val animator = uut.showAnimator
uut.show()
assertThat(animator).isEqualTo(uut.showAnimator)
}
@Test
fun show_updatesTranslationDy() {
view.visibility = View.GONE
val options = spy<AnimationOptions>()
whenever(options.hasValue()).thenReturn(true)
uut.show(options, 123f)
verify(options).setValueDy(View.TRANSLATION_Y, -123f, 0f)
}
@Test
fun show_usesDefaultShowAnimatorIfAnimationIsNotSpecifiedInOptions() {
view.visibility = View.GONE
uut.show(mock())
assertThat(uut.showAnimator).isEqualTo(defaultShowAnimator)
}
@Test
fun hide() {
assertNotAnimating()
val onAnimationEnd = mock<Runnable>()
uut.hide(mock(), 0f, onAnimationEnd)
assertAnimatingHide()
uut.hideAnimator.end()
verify(onAnimationEnd).run()
}
@Test
fun hide_doesNothingIfAlreadyAnimatingHide() {
uut.hide(mock())
val animator = uut.hideAnimator
uut.hide(mock())
assertThat(animator).isEqualTo(uut.hideAnimator)
}
@Test
fun hide_updatesTranslationDy() {
val options = spy<AnimationOptions>()
whenever(options.hasValue()).thenReturn(true)
uut.hide(options, 123f)
verify(options).setValueDy(View.TRANSLATION_Y, 0f, -123f)
}
@Test
fun hide_usesDefaultHideAnimatorIfAnimationIsNotSpecifiedInOptions() {
uut.hide(mock())
assertThat(uut.hideAnimator).isEqualTo(defaultHideAnimator)
}
private fun assertNotAnimating() = assertThat(uut.isAnimatingHide() && uut.isAnimatingShow()).isFalse()
private fun assertAnimatingShow() = assertThat(uut.isAnimatingShow() && !uut.isAnimatingHide()).isTrue()
private fun assertAnimatingHide() = assertThat(uut.isAnimatingHide() && !uut.isAnimatingShow()).isTrue()
}