diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt index a073bc60ff55..fa24c504af05 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt @@ -62,7 +62,9 @@ private val DUMMY_RELAY_COUNTRY_2 = ) private val DUMMY_WIREGUARD_PORT_RANGES = ArrayList() -private val DUMMY_WIREGUARD_ENDPOINT_DATA = WireguardEndpointData(DUMMY_WIREGUARD_PORT_RANGES) +private val DUMMY_SHADOWSOCKS_PORT_RANGES = emptyList() +private val DUMMY_WIREGUARD_ENDPOINT_DATA = + WireguardEndpointData(DUMMY_WIREGUARD_PORT_RANGES, DUMMY_SHADOWSOCKS_PORT_RANGES) val DUMMY_RELAY_COUNTRIES = listOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/dialog/CustomPortDialogTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/dialog/CustomPortDialogTest.kt index ec304952651c..7ca4d7f3d4b0 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/dialog/CustomPortDialogTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/dialog/CustomPortDialogTest.kt @@ -21,7 +21,6 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.test.CUSTOM_PORT_DIALOG_INPUT_TEST_TAG import net.mullvad.mullvadvpn.lib.model.PortRange import net.mullvad.mullvadvpn.onNodeWithTagAndText -import net.mullvad.mullvadvpn.viewmodel.WireguardCustomPortDialogUiState import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension @@ -40,6 +39,7 @@ class CustomPortDialogTest { @SuppressLint("ComposableNaming") @Composable private fun testWireguardCustomPortDialog( + title: String = "", portInput: String = "", isValidInput: Boolean = false, showResetToDefault: Boolean = false, @@ -49,16 +49,12 @@ class CustomPortDialogTest { onResetPort: () -> Unit = {}, onDismiss: () -> Unit = {}, ) { - val state = - WireguardCustomPortDialogUiState( - portInput = portInput, - isValidInput = isValidInput, - allowedPortRanges = allowedPortRanges, - showResetToDefault = showResetToDefault, - ) - - WireguardCustomPortDialog( - state, + CustomPortDialog( + title = title, + portInput = portInput, + isValidInput = isValidInput, + showResetToDefault = showResetToDefault, + allowedPortRanges = allowedPortRanges, onInputChanged = onInputChanged, onSavePort = onSavePort, onDismiss = onDismiss, diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ShadowsocksSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ShadowsocksSettingsScreenTest.kt new file mode 100644 index 000000000000..23d94f58c6a3 --- /dev/null +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ShadowsocksSettingsScreenTest.kt @@ -0,0 +1,56 @@ +package net.mullvad.mullvadvpn.compose.screen + +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import io.mockk.mockk +import io.mockk.verify +import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension +import net.mullvad.mullvadvpn.compose.setContentWithTheme +import net.mullvad.mullvadvpn.compose.state.ShadowsocksSettingsState +import net.mullvad.mullvadvpn.compose.test.SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG +import net.mullvad.mullvadvpn.lib.model.Constraint +import net.mullvad.mullvadvpn.lib.model.Port +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.RegisterExtension + +@OptIn(ExperimentalTestApi::class) +class ShadowsocksSettingsScreenTest { + @JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() + + @Test + fun testShowShadowsocksCustomPort() = + composeExtension.use { + // Arrange + setContentWithTheme { + ShadowsocksSettingsScreen(state = ShadowsocksSettingsState(customPort = Port(4000))) + } + + // Assert + onNodeWithText("4000").assertExists() + } + + @Test + fun testSelectShadowsocksCustomPort() = + composeExtension.use { + // Arrange + val onObfuscationPortSelected: (Constraint) -> Unit = mockk(relaxed = true) + setContentWithTheme { + ShadowsocksSettingsScreen( + state = + ShadowsocksSettingsState( + port = Constraint.Only(Port(4000)), + customPort = Port(4000), + ), + onObfuscationPortSelected = onObfuscationPortSelected, + ) + } + + // Act + onNodeWithTag(testTag = SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG).performClick() + + // Assert + verify { onObfuscationPortSelected.invoke(Constraint.Only(Port(4000))) } + } +} diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/Udp2TcpSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/Udp2TcpSettingsScreenTest.kt new file mode 100644 index 000000000000..77b9965b26b0 --- /dev/null +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/Udp2TcpSettingsScreenTest.kt @@ -0,0 +1,44 @@ +package net.mullvad.mullvadvpn.compose.screen + +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.performClick +import io.mockk.coVerify +import io.mockk.mockk +import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension +import net.mullvad.mullvadvpn.compose.setContentWithTheme +import net.mullvad.mullvadvpn.compose.state.Udp2TcpSettingsState +import net.mullvad.mullvadvpn.compose.test.UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG +import net.mullvad.mullvadvpn.lib.model.Constraint +import net.mullvad.mullvadvpn.lib.model.Port +import net.mullvad.mullvadvpn.onNodeWithTagAndText +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.RegisterExtension + +@OptIn(ExperimentalTestApi::class) +class Udp2TcpSettingsScreenTest { + @JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() + + @Test + fun testSelectTcpOverUdpPortOption() = + composeExtension.use { + // Arrange + val onObfuscationPortSelected: (Constraint) -> Unit = mockk(relaxed = true) + setContentWithTheme { + Udp2TcpSettingsScreen( + state = Udp2TcpSettingsState(port = Constraint.Any), + onObfuscationPortSelected = onObfuscationPortSelected, + ) + } + + // Act + onNodeWithTagAndText( + testTag = String.format(UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001), + text = "5001", + ) + .assertExists() + .performClick() + + // Assert + coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(5001))) } + } +} diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index b2079e0e782e..a15875477a07 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -8,7 +8,6 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollToNode import io.mockk.MockKAnnotations -import io.mockk.coVerify import io.mockk.mockk import io.mockk.verify import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension @@ -18,17 +17,15 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_QUANTUM_ITEM_ON_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_TEST_TAG -import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG -import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG +import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.Mtu import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.PortRange import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.onNodeWithTagAndText import net.mullvad.mullvadvpn.viewmodel.CustomDnsItem import org.junit.jupiter.api.BeforeEach @@ -206,74 +203,6 @@ class VpnSettingsScreenTest { onNodeWithContentDescription(LOCAL_DNS_SERVER_WARNING).assertExists() } - @Test - fun testSelectTcpOverUdpPortOption() = - composeExtension.use { - // Arrange - val onObfuscationPortSelected: (Constraint) -> Unit = mockk(relaxed = true) - setContentWithTheme { - VpnSettingsScreen( - state = - VpnSettingsUiState.createDefault( - selectedObfuscation = SelectedObfuscation.Udp2Tcp, - selectedObfuscationPort = Constraint.Only(Port(5001)), - ), - onObfuscationPortSelected = onObfuscationPortSelected, - ) - } - - // Act - onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG)) - onNodeWithText("UDP-over-TCP port").performClick() - onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode( - hasTestTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001)) - ) - - // Assert - onNodeWithTagAndText( - testTag = String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001), - text = "5001", - ) - .assertExists() - .performClick() - - coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(5001))) } - } - - @Test - fun testAttemptSelectTcpOverUdpPortOption() = - composeExtension.use { - // Arrange - val onObfuscationPortSelected: (Constraint) -> Unit = mockk(relaxed = true) - setContentWithTheme { - VpnSettingsScreen( - state = - VpnSettingsUiState.createDefault( - selectedObfuscation = SelectedObfuscation.Off - ), - onObfuscationPortSelected = onObfuscationPortSelected, - ) - } - - // Act - onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG)) - onNodeWithText("UDP-over-TCP port").performClick() - onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode( - hasTestTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001)) - ) - - // Assert - onNodeWithTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001)) - .assertExists() - .performClick() - - verify(exactly = 0) { onObfuscationPortSelected.invoke(any()) } - } - @Test fun testShowSelectedTunnelQuantumOption() = composeExtension.use { @@ -386,10 +315,7 @@ class VpnSettingsScreenTest { // Arrange setContentWithTheme { VpnSettingsScreen( - state = - VpnSettingsUiState.createDefault( - customWireguardPort = Constraint.Only(Port(4000)) - ) + state = VpnSettingsUiState.createDefault(customWireguardPort = Port(4000)) ) } @@ -411,7 +337,7 @@ class VpnSettingsScreenTest { state = VpnSettingsUiState.createDefault( selectedWireguardPort = Constraint.Only(Port(4000)), - customWireguardPort = Constraint.Only(Port(4000)), + customWireguardPort = Port(4000), ), onWireguardPortSelected = onWireguardPortSelected, ) @@ -483,9 +409,8 @@ class VpnSettingsScreenTest { } // Act - onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG)) + .performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG)) onNodeWithText("WireGuard obfuscation").performClick() // Assert