summaryrefslogtreecommitdiffhomepage
path: root/android/app/src/androidTest
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-09-11 11:41:25 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-09-29 10:18:56 +0200
commit9cce937c14bdc77b1dc0ad2589fd342485a18e43 (patch)
tree215fdf431ba9eb583185f725be4e523d48411cd8 /android/app/src/androidTest
parent4d1cd356f586b7e84380869465fa752b25115156 (diff)
downloadmullvadvpn-9cce937c14bdc77b1dc0ad2589fd342485a18e43.tar.xz
mullvadvpn-9cce937c14bdc77b1dc0ad2589fd342485a18e43.zip
Disable keybaords for flaky tests and enable them again
The combination of the keyboard appearing at the same time as input being from the test causes a crash during some circumstances.
Diffstat (limited to 'android/app/src/androidTest')
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt26
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/EditApiAccessMethodScreenTest.kt37
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/util/Keyboard.kt22
3 files changed, 58 insertions, 27 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt
index 63c6ecef95..2e4b25b5ca 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt
@@ -14,13 +14,13 @@ import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_COUNTRIES
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsData
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
+import net.mullvad.mullvadvpn.compose.util.DisableSoftKeyboard
import net.mullvad.mullvadvpn.lib.model.RelayItem
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.CheckableRelayListItem
import net.mullvad.mullvadvpn.lib.ui.tag.CIRCULAR_PROGRESS_INDICATOR_TEST_TAG
import net.mullvad.mullvadvpn.lib.ui.tag.SAVE_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.util.Lce
import org.junit.jupiter.api.BeforeEach
-import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
@@ -40,17 +40,19 @@ class CustomListLocationsScreenTest {
onRelaySelectionClick: (RelayItem.Location, selected: Boolean) -> Unit = { _, _ -> },
onExpand: (RelayItem.Location, selected: Boolean) -> Unit = { _, _ -> },
onBackClick: () -> Unit = {},
+ disableKeyboard: Boolean = false,
) {
-
setContentWithTheme {
- CustomListLocationsScreen(
- state = state,
- onSearchTermInput = onSearchTermInput,
- onSaveClick = onSaveClick,
- onRelaySelectionClick = onRelaySelectionClick,
- onExpand = onExpand,
- onBackClick = onBackClick,
- )
+ DisableSoftKeyboard(disable = disableKeyboard) {
+ CustomListLocationsScreen(
+ state = state,
+ onSearchTermInput = onSearchTermInput,
+ onSaveClick = onSaveClick,
+ onRelaySelectionClick = onRelaySelectionClick,
+ onExpand = onExpand,
+ onBackClick = onBackClick,
+ )
+ }
}
}
@@ -161,7 +163,6 @@ class CustomListLocationsScreenTest {
}
@Test
- @Disabled("Text input is flaky see DROID-2140 for more details")
fun whenSearchInputIsUpdatedShouldCallOnSearchTermInput() =
composeExtension.use {
// Arrange
@@ -181,6 +182,9 @@ class CustomListLocationsScreenTest {
),
),
onSearchTermInput = mockedSearchTermInput,
+ // This is required to avoid a crash due to the keyboard trying to open at the same
+ // time as the test makes input
+ disableKeyboard = true,
)
val mockSearchString = "SEARCH"
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/EditApiAccessMethodScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/EditApiAccessMethodScreenTest.kt
index 1d8c0c7beb..a22048d69b 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/EditApiAccessMethodScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/EditApiAccessMethodScreenTest.kt
@@ -13,11 +13,11 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.ApiAccessMethodTypes
import net.mullvad.mullvadvpn.compose.state.EditApiAccessFormData
import net.mullvad.mullvadvpn.compose.state.EditApiAccessMethodUiState
+import net.mullvad.mullvadvpn.compose.util.DisableSoftKeyboard
import net.mullvad.mullvadvpn.lib.model.Cipher
import net.mullvad.mullvadvpn.lib.model.InvalidDataError
import net.mullvad.mullvadvpn.lib.model.ParsePortError
import net.mullvad.mullvadvpn.lib.ui.tag.EDIT_API_ACCESS_NAME_INPUT_TEST_TAG
-import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
@@ -38,22 +38,25 @@ class EditApiAccessMethodScreenTest {
onTestMethod: () -> Unit = {},
onAddMethod: () -> Unit = {},
onNavigateBack: () -> Unit = {},
+ disableKeyboard: Boolean = false,
) {
setContentWithTheme {
- EditApiAccessMethodScreen(
- state = state,
- onNameChanged = onNameChanged,
- onTypeSelected = onTypeSelected,
- onIpChanged = onIpChanged,
- onPortChanged = onPortChanged,
- onPasswordChanged = onPasswordChanged,
- onCipherChange = onCipherChange,
- onToggleAuthenticationEnabled = onToggleAuthenticationEnabled,
- onUsernameChanged = onUsernameChanged,
- onTestMethod = onTestMethod,
- onAddMethod = onAddMethod,
- onNavigateBack = onNavigateBack,
- )
+ DisableSoftKeyboard(disable = disableKeyboard) {
+ EditApiAccessMethodScreen(
+ state = state,
+ onNameChanged = onNameChanged,
+ onTypeSelected = onTypeSelected,
+ onIpChanged = onIpChanged,
+ onPortChanged = onPortChanged,
+ onPasswordChanged = onPasswordChanged,
+ onCipherChange = onCipherChange,
+ onToggleAuthenticationEnabled = onToggleAuthenticationEnabled,
+ onUsernameChanged = onUsernameChanged,
+ onTestMethod = onTestMethod,
+ onAddMethod = onAddMethod,
+ onNavigateBack = onNavigateBack,
+ )
+ }
}
}
@@ -175,7 +178,6 @@ class EditApiAccessMethodScreenTest {
}
@Test
- @Disabled("Text input is flaky see DROID-2140 for more details")
fun whenNameInputChangesShouldCallOnNameChanged() =
composeExtension.use {
// Arrange
@@ -190,6 +192,9 @@ class EditApiAccessMethodScreenTest {
isTestingApiAccessMethod = false,
),
onNameChanged = onNameChanged,
+ // This is required to avoid a crash due to the keyboard trying to open at the same
+ // time as the test makes input
+ disableKeyboard = true,
)
// Act
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/util/Keyboard.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/util/Keyboard.kt
new file mode 100644
index 0000000000..024fd49407
--- /dev/null
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/util/Keyboard.kt
@@ -0,0 +1,22 @@
+package net.mullvad.mullvadvpn.compose.util
+
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.ExperimentalComposeUiApi
+import androidx.compose.ui.platform.InterceptPlatformTextInput
+import kotlinx.coroutines.awaitCancellation
+
+// Stackoverflow answer: https://stackoverflow.com/a/78720287
+@OptIn(ExperimentalComposeUiApi::class)
+@Composable
+fun DisableSoftKeyboard(disable: Boolean = true, content: @Composable () -> Unit) {
+ InterceptPlatformTextInput(
+ interceptor = { request, nextHandler ->
+ if (!disable) {
+ nextHandler.startInputMethod(request)
+ } else {
+ awaitCancellation()
+ }
+ },
+ content = content,
+ )
+}