Skip to content

Commit 7ddb0b3

Browse files
committed
Restrict theme override to floating button
1 parent 8f0b5c6 commit 7ddb0b3

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
}

code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/alert/AlertPresentable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class AlertPresentable(
4444
mainScope
4545
) {
4646
override fun getContent(activityContext: Context): ComposeView {
47-
return ComposeView(getThemedContext(activityContext)).apply {
47+
return ComposeView(activityContext).apply {
4848
setContent {
4949
AlertScreen(
5050
presentationStateManager = presentationStateManager,

code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/InAppMessagePresentable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal class InAppMessagePresentable(
7777
* @param activityContext the context of the activity
7878
*/
7979
override fun getContent(activityContext: Context): ComposeView {
80-
return ComposeView(getThemedContext(activityContext)).apply {
80+
return ComposeView(activityContext).apply {
8181
layoutParams = ViewGroup.LayoutParams(
8282
ViewGroup.LayoutParams.MATCH_PARENT,
8383
ViewGroup.LayoutParams.MATCH_PARENT

0 commit comments

Comments
 (0)