Skip to content

Commit b61d937

Browse files
committed
Add new test
1 parent d1d3bd6 commit b61d937

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/OpacityCore.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ object OpacityCore {
4646
@JvmStatic
4747
fun setContext(context: Context) {
4848
appContext = context
49-
sRuntime = GeckoRuntime.create(appContext.applicationContext)
49+
// Only create GeckoRuntime if it hasn't been created yet
50+
if (!::sRuntime.isInitialized) {
51+
sRuntime = GeckoRuntime.create(appContext.applicationContext)
52+
}
5053
cryptoManager = CryptoManager(appContext.applicationContext)
5154
}
5255

app/src/androidTest/java/UITests.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,21 @@ class UITests {
4646
)
4747
)
4848
}
49+
50+
@Test
51+
fun testSuccessFlowButton() {
52+
// Check if button is displayed
53+
composeTestRule.onNodeWithText("Test flow always succeeds").assertIsDisplayed()
54+
55+
// Perform click
56+
composeTestRule.onNodeWithText("Test flow always succeeds").performClick()
57+
58+
// Wait for the async operation to complete
59+
Thread.sleep(3000)
60+
61+
// Check that the success dialog is displayed
62+
composeTestRule.onNodeWithText("Success").assertIsDisplayed()
63+
composeTestRule.onNodeWithText("Test flow completed successfully!").assertIsDisplayed()
64+
composeTestRule.onNodeWithText("OK").assertIsDisplayed()
65+
}
4966
}

app/src/main/java/com/opacitylabs/opacitycoreexample/MainActivity.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import androidx.activity.enableEdgeToEdge
99
import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.fillMaxSize
1111
import androidx.compose.foundation.layout.padding
12+
import androidx.compose.material3.AlertDialog
1213
import androidx.compose.material3.Button
1314
import androidx.compose.material3.Scaffold
1415
import androidx.compose.material3.Text
16+
import androidx.compose.material3.TextButton
1517
import androidx.compose.material3.TextField
18+
import androidx.compose.runtime.getValue
1619
import androidx.compose.runtime.mutableStateOf
1720
import androidx.compose.runtime.remember
21+
import androidx.compose.runtime.setValue
1822
import androidx.compose.ui.Modifier
1923
import androidx.lifecycle.lifecycleScope
2024
import com.opacitylabs.opacitycore.JsonConverter
@@ -59,6 +63,22 @@ class MainActivity : ComponentActivity() {
5963
enableEdgeToEdge()
6064
setContent {
6165
OpacityCoreExampleTheme {
66+
var showSuccessDialog by remember { mutableStateOf(false) }
67+
68+
// Success dialog
69+
if (showSuccessDialog) {
70+
AlertDialog(
71+
onDismissRequest = { showSuccessDialog = false },
72+
title = { Text("Success") },
73+
text = { Text("Test flow completed successfully!") },
74+
confirmButton = {
75+
TextButton(onClick = { showSuccessDialog = false }) {
76+
Text("OK")
77+
}
78+
}
79+
)
80+
}
81+
6282
Scaffold(
6383
modifier = Modifier.fillMaxSize(),
6484
containerColor = androidx.compose.ui.graphics.Color.Black
@@ -174,6 +194,32 @@ class MainActivity : ComponentActivity() {
174194
}
175195
},
176196
) { Text(text = "Uber Rider Profile") }
197+
Button(
198+
onClick = {
199+
lifecycleScope.launch {
200+
val res =
201+
OpacityCore.get("test:open_browser_must_succeed", null)
202+
res.fold(
203+
onSuccess = { value ->
204+
Log.e(
205+
"MainActivity",
206+
"Res: ${value}value"
207+
)
208+
showSuccessDialog = true
209+
},
210+
onFailure = {
211+
when (it) {
212+
is OpacityError -> Log.e(
213+
"MainActivity",
214+
"code: ${it.code}, message: ${it.message}"
215+
)
216+
217+
else -> Log.e("MainActivity", it.toString())
218+
}
219+
})
220+
}
221+
},
222+
) { Text(text = "Test flow always succeeds") }
177223
}
178224
}
179225
}

0 commit comments

Comments
 (0)