-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathReplayLifecycleTest.kt
More file actions
116 lines (91 loc) · 3.68 KB
/
ReplayLifecycleTest.kt
File metadata and controls
116 lines (91 loc) · 3.68 KB
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
110
111
112
113
114
115
116
package io.sentry.android.replay
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class ReplayLifecycleTest {
@Test
fun `verify initial state`() {
val lifecycle = ReplayLifecycle()
assertEquals(ReplayState.INITIAL, lifecycle.currentState)
}
@Test
fun `test transitions from INITIAL state`() {
val lifecycle = ReplayLifecycle()
assertTrue(lifecycle.isAllowed(ReplayState.STARTED))
assertTrue(lifecycle.isAllowed(ReplayState.CLOSED))
assertFalse(lifecycle.isAllowed(ReplayState.RESUMED))
assertFalse(lifecycle.isAllowed(ReplayState.PAUSED))
assertFalse(lifecycle.isAllowed(ReplayState.STOPPED))
}
@Test
fun `test transitions from STARTED state`() {
val lifecycle = ReplayLifecycle()
lifecycle.currentState = ReplayState.STARTED
assertTrue(lifecycle.isAllowed(ReplayState.RESUMED))
assertTrue(lifecycle.isAllowed(ReplayState.PAUSED))
assertTrue(lifecycle.isAllowed(ReplayState.STOPPED))
assertTrue(lifecycle.isAllowed(ReplayState.CLOSED))
assertFalse(lifecycle.isAllowed(ReplayState.INITIAL))
}
@Test
fun `test transitions from RESUMED state`() {
val lifecycle = ReplayLifecycle()
lifecycle.currentState = ReplayState.RESUMED
assertTrue(lifecycle.isAllowed(ReplayState.PAUSED))
assertTrue(lifecycle.isAllowed(ReplayState.STOPPED))
assertTrue(lifecycle.isAllowed(ReplayState.CLOSED))
assertFalse(lifecycle.isAllowed(ReplayState.STARTED))
assertFalse(lifecycle.isAllowed(ReplayState.INITIAL))
}
@Test
fun `test transitions from PAUSED state`() {
val lifecycle = ReplayLifecycle()
lifecycle.currentState = ReplayState.PAUSED
assertTrue(lifecycle.isAllowed(ReplayState.RESUMED))
assertTrue(lifecycle.isAllowed(ReplayState.STOPPED))
assertTrue(lifecycle.isAllowed(ReplayState.CLOSED))
assertFalse(lifecycle.isAllowed(ReplayState.STARTED))
assertFalse(lifecycle.isAllowed(ReplayState.INITIAL))
}
@Test
fun `test transitions from STOPPED state`() {
val lifecycle = ReplayLifecycle()
lifecycle.currentState = ReplayState.STOPPED
assertTrue(lifecycle.isAllowed(ReplayState.STARTED))
assertTrue(lifecycle.isAllowed(ReplayState.CLOSED))
assertFalse(lifecycle.isAllowed(ReplayState.RESUMED))
assertFalse(lifecycle.isAllowed(ReplayState.PAUSED))
assertFalse(lifecycle.isAllowed(ReplayState.INITIAL))
}
@Test
fun `test transitions from CLOSED state`() {
val lifecycle = ReplayLifecycle()
lifecycle.currentState = ReplayState.CLOSED
assertFalse(lifecycle.isAllowed(ReplayState.INITIAL))
assertFalse(lifecycle.isAllowed(ReplayState.STARTED))
assertFalse(lifecycle.isAllowed(ReplayState.RESUMED))
assertFalse(lifecycle.isAllowed(ReplayState.PAUSED))
assertFalse(lifecycle.isAllowed(ReplayState.STOPPED))
assertFalse(lifecycle.isAllowed(ReplayState.CLOSED))
}
@Test
fun `test touch recording is allowed only in STARTED and RESUMED states`() {
val lifecycle = ReplayLifecycle()
// Initial state doesn't allow touch recording
assertFalse(lifecycle.isTouchRecordingAllowed())
// STARTED state allows touch recording
lifecycle.currentState = ReplayState.STARTED
assertTrue(lifecycle.isTouchRecordingAllowed())
// RESUMED state allows touch recording
lifecycle.currentState = ReplayState.RESUMED
assertTrue(lifecycle.isTouchRecordingAllowed())
// Other states don't allow touch recording
val otherStates =
listOf(ReplayState.INITIAL, ReplayState.PAUSED, ReplayState.STOPPED, ReplayState.CLOSED)
otherStates.forEach { state ->
lifecycle.currentState = state
assertFalse(lifecycle.isTouchRecordingAllowed())
}
}
}