Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the test app for smoke testing (core/lifecycle/signal) #695

Merged
merged 15 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified code/testapp/src/main/assets/ADBMobileConfig-rules.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -38,7 +37,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.adobe.marketing.mobile.LoggingMode
Expand All @@ -47,19 +45,10 @@ import com.adobe.marketing.mobile.MobilePrivacyStatus
import com.adobe.marketing.mobile.core.testapp.ui.theme.AEPSDKCoreAndroidTheme
import com.adobe.marketing.mobile.services.Log
import com.adobe.marketing.mobile.services.ServiceProvider
import kotlinx.coroutines.delay

@Composable
fun CoreView(navController: NavHostController) {
var appId by remember { mutableStateOf("your-appId") }
var showNetworkRequest by remember { mutableStateOf(false) }
LaunchedEffect(showNetworkRequest) {
if (showNetworkRequest) {
delay(1000)
showAlert("Network Request: ${SDKObserver.getLatestNetworkRequest()?.url}")
showNetworkRequest = false
}
}
Column(Modifier.padding(8.dp)) {
Button(onClick = {
navController.navigate(NavRoutes.HomeView.route)
Expand All @@ -77,22 +66,6 @@ fun CoreView(navController: NavHostController) {
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = {
showCoreVersion()
}) {
Text(text = "extensionVersion")
}
Button(onClick = {
SDKObserver.getLatestConfiguration()?.let {
showAlert("latestConfiguration: $it")
} ?: run {
showAlert("latestConfiguration: null")
}
}) {
Text(text = "latestConfiguration")
}

Button(onClick = {
SDKObserver.clearLatestConfiguration()
MobileCore.configureWithFileInAssets("ADBMobileConfig_custom.json")
}) {
Text(text = "configureWithFileInAssets()")
Expand All @@ -112,7 +85,6 @@ fun CoreView(navController: NavHostController) {
label = { Text("appId") }
)
Button(onClick = {
SDKObserver.clearLatestConfiguration()
MobileCore.configureWithAppID(appId)
}) {
Text(text = "configureWithAppID(\"appId\")")
Expand Down Expand Up @@ -149,9 +121,8 @@ fun CoreView(navController: NavHostController) {
Text(text = "getPrivacyStatus")
}
Button(onClick = {
SDKObserver.clearLatestNetworkRequest()
MobileCore.trackAction("action", null)
showNetworkRequest = true
// The bundled rule is configured to triggers a postbackk for the following condition: a trackAction event with the action type 'bundled_trigger_postback'.
yangyansong-adbe marked this conversation as resolved.
Show resolved Hide resolved
MobileCore.trackAction("bundled_trigger_postback", null)
}) {
Text(text = "trigger rule consequence(postback)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -31,18 +26,9 @@ import androidx.navigation.compose.rememberNavController
import com.adobe.marketing.mobile.MobileCore
import com.adobe.marketing.mobile.Signal
import com.adobe.marketing.mobile.core.testapp.ui.theme.AEPSDKCoreAndroidTheme
import kotlinx.coroutines.delay

@Composable
fun LifecycleView(navController: NavHostController) {
var showLifecycleEvent by remember { mutableStateOf(false) }
LaunchedEffect(showLifecycleEvent) {
if (showLifecycleEvent) {
delay(1000)
showAlert("Lifecycle event: ${SDKObserver.getLatestLifecycleEvent()?.toString()}")
showLifecycleEvent = false
}
}
Column(Modifier.padding(8.dp)) {
Button(onClick = {
navController.navigate(NavRoutes.HomeView.route)
Expand All @@ -56,23 +42,17 @@ fun LifecycleView(navController: NavHostController) {
) {
Text(text = "Signal extension version - ${Signal.extensionVersion()}")
Button(onClick = {
SDKObserver.clearLatestLifecycleEvent()
MobileCore.lifecycleStart(null)
showLifecycleEvent = true
}) {
Text(text = "lifecycleStart")
}
Button(onClick = {
SDKObserver.clearLatestLifecycleEvent()
MobileCore.lifecycleStart(mapOf("key" to "value"))
showLifecycleEvent = true
}) {
Text(text = "lifecycleStart(contextData)")
}
Button(onClick = {
SDKObserver.clearLatestLifecycleEvent()
MobileCore.lifecyclePause()
showLifecycleEvent = true
}) {
Text(text = "lifecyclePause")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MyApp : Application() {
// MobileCore.configureWithAppID("YOUR_APP_ID")
val extensions = listOf(Identity.EXTENSION, Signal.EXTENSION, Lifecycle.EXTENSION, PerfExtension::class.java)
MobileCore.registerExtensions(extensions) {}
SDKObserver.init()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,14 @@ fun SignalView(navController: NavHostController) {
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Example of the malformed URL: https://www.adobe.com:_80/", fontSize = 10.sp)
OutlinedTextField(
value = url,
onValueChange = { url = it },
label = { Text("URL") }
)
Button(onClick = {
MobileCore.dispatchEvent(
Event.Builder("consequence event", EventType.RULES_ENGINE, EventSource.RESPONSE_CONTENT).setEventData(
mapOf(
"triggeredconsequence" to mapOf(
"type" to "pii",
"detail" to mapOf(
"timeout" to 0,
"templateurl" to url
)
)
)
).build())
Text(text = "Signal extension version - ${Signal.extensionVersion()}")

Button(onClick = {
// To test this, configure a rule in your launch property that triggers a postbackk for the following condition: a trackAction event with the action type 'trigger_postback'.
MobileCore.trackAction("trigger_postback", null)
}) {
Text(text = "post back")
Text(text = "trigger rule consequence(postback)")
}
// openURL is covered by automation test, we can enable it later if needed for customer issue verification
Button(onClick = {},enabled = false) {
Text(text = "open URL")
}
Text(text = "Signal extension version - ${Signal.extensionVersion()}")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
*/
package com.adobe.marketing.mobile.core.testapp

import android.app.Service
import com.adobe.marketing.mobile.Event
import com.adobe.marketing.mobile.EventSource
import com.adobe.marketing.mobile.EventType
import com.adobe.marketing.mobile.MobileCore
import com.adobe.marketing.mobile.services.NetworkRequest
import com.adobe.marketing.mobile.services.ObservableNetworkService
import com.adobe.marketing.mobile.services.ServiceProvider
import com.adobe.marketing.mobile.services.ui.Alert
import com.adobe.marketing.mobile.services.ui.Presentable
Expand All @@ -35,59 +29,29 @@ internal val alertEventListener = object : AlertEventListener {
}

internal fun showAlert(event: Event) {
val alert = Alert(AlertSettings.Builder()
.title("Event")
.message(event.toString())
.positiveButtonText("OK")
.build()
, alertEventListener)

val alertPresentable = ServiceProvider.getInstance().uiService.create(alert, DefaultPresentationUtilityProvider())
val alert = Alert(
AlertSettings.Builder()
.title("Event")
.message(event.toString())
.positiveButtonText("OK")
.build(), alertEventListener
)

val alertPresentable =
ServiceProvider.getInstance().uiService.create(alert, DefaultPresentationUtilityProvider())
alertPresentable.show()
}

internal fun showAlert(message: String) {
val alert = Alert(AlertSettings.Builder()
.title("Message")
.message(message)
.positiveButtonText("OK")
.build()
, alertEventListener)

val alertPresentable = ServiceProvider.getInstance().uiService.create(alert, DefaultPresentationUtilityProvider())
val alert = Alert(
AlertSettings.Builder()
.title("Message")
.message(message)
.positiveButtonText("OK")
.build(), alertEventListener
)

val alertPresentable =
ServiceProvider.getInstance().uiService.create(alert, DefaultPresentationUtilityProvider())
alertPresentable.show()
}

internal object SDKObserver{
fun init(){
MobileCore.registerEventListener(EventType.CONFIGURATION, EventSource.RESPONSE_CONTENT) {
latestConfiguration = it.eventData
}
MobileCore.registerEventListener(EventType.GENERIC_LIFECYCLE, EventSource.REQUEST_CONTENT) {
latestLifecycleEvent = it
}
ServiceProvider.getInstance().networkService = ObservableNetworkService { latestNetworkRequest = it }
}
private var latestConfiguration: Map<String,Any>? = null
private var latestNetworkRequest: NetworkRequest? = null
private var latestLifecycleEvent: Event? = null

fun clearLatestLifecycleEvent() {
latestLifecycleEvent = null
}
fun getLatestLifecycleEvent(): Event? {
return latestLifecycleEvent
}
fun clearLatestNetworkRequest() {
latestNetworkRequest = null
}
fun getLatestNetworkRequest(): NetworkRequest? {
return latestNetworkRequest
}
fun getLatestConfiguration(): Map<String,Any>? {
return latestConfiguration
}
fun clearLatestConfiguration() {
latestConfiguration = null
}
}