1
+ import android.content.Context
2
+ import android.view.ContextThemeWrapper
3
+ import androidx.test.core.app.ApplicationProvider
4
+ import com.adobe.marketing.mobile.core.R
5
+ import com.adobe.marketing.mobile.services.ui.FloatingButton
6
+ import com.adobe.marketing.mobile.services.ui.PresentationDelegate
7
+ import com.adobe.marketing.mobile.services.ui.PresentationUtilityProvider
8
+ import com.adobe.marketing.mobile.services.ui.common.AppLifecycleProvider
9
+ import com.adobe.marketing.mobile.services.ui.floatingbutton.FloatingButtonPresentable
10
+ import com.adobe.marketing.mobile.services.ui.floatingbutton.FloatingButtonSettings
11
+ import com.adobe.marketing.mobile.services.ui.floatingbutton.FloatingButtonViewModel
12
+ import junit.framework.TestCase.assertTrue
13
+ import kotlinx.coroutines.CoroutineScope
14
+ import kotlinx.coroutines.Dispatchers
15
+ import kotlinx.coroutines.test.runTest
16
+ import org.junit.Before
17
+ import org.junit.Test
18
+ import org.mockito.Mock
19
+ import org.mockito.Mockito.`when`
20
+ import org.mockito.Mockito.mock
21
+ import org.mockito.MockitoAnnotations
22
+
23
+ class FloatingButtonPresentableTests {
24
+ @Mock
25
+ private lateinit var mockFloatingButton: FloatingButton
26
+
27
+ @Mock
28
+ private lateinit var mockFloatingButtonSettings: FloatingButtonSettings
29
+
30
+ @Before
31
+ fun setUp () {
32
+ MockitoAnnotations .openMocks(this )
33
+
34
+ // Mock the settings and initial graphic
35
+ `when `(mockFloatingButton.settings).thenReturn(mockFloatingButtonSettings)
36
+ `when `(mockFloatingButtonSettings.initialGraphic).thenReturn(mock(android.graphics.Bitmap ::class .java))
37
+ }
38
+
39
+ @Test
40
+ fun test_getContentReturnsComposeViewWithThemeWrapper () = runTest {
41
+ // setup
42
+ val context = ApplicationProvider .getApplicationContext<Context >()
43
+ val floatingButtonViewModel = mock(FloatingButtonViewModel ::class .java)
44
+ val presentationDelegate = mock(PresentationDelegate ::class .java)
45
+ val presentationUtilityProvider = mock(PresentationUtilityProvider ::class .java)
46
+ val appLifecycleProvider = mock(AppLifecycleProvider ::class .java)
47
+ val mainScope = CoroutineScope (Dispatchers .Main )
48
+
49
+ val presentable = FloatingButtonPresentable (
50
+ mockFloatingButton,
51
+ floatingButtonViewModel,
52
+ presentationDelegate,
53
+ presentationUtilityProvider,
54
+ appLifecycleProvider,
55
+ mainScope
56
+ )
57
+
58
+ // test
59
+ val composeView = presentable.getContent(context)
60
+
61
+ // verify
62
+ assertTrue(composeView.context is ContextThemeWrapper )
63
+ val themedContext = composeView.context as ContextThemeWrapper
64
+ val theme = themedContext.theme
65
+ // get android.background from the theme
66
+ val background = theme.obtainStyledAttributes(intArrayOf(android.R .attr.background))
67
+ assertTrue(background.hasValue(0 )
68
+ && background.peekValue(0 ).resourceId == android.R .color.transparent)
69
+ }
70
+ }
0 commit comments