diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-03-06 15:25:25 +0100 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-03-07 11:27:47 +0100 |
| commit | c17b6fa0d465dd39c9cefa7fe69af23031b67189 (patch) | |
| tree | a14c4a13d4e5d7ecac41a3d0f9f2e2110370c70d /android/app/src | |
| parent | c2f164d8cde3d854a4f3cfc7d67f523215ee56d1 (diff) | |
| download | mullvadvpn-c17b6fa0d465dd39c9cefa7fe69af23031b67189.tar.xz mullvadvpn-c17b6fa0d465dd39c9cefa7fe69af23031b67189.zip | |
Fix and add tests
Diffstat (limited to 'android/app/src')
5 files changed, 48 insertions, 1 deletions
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 13ef28dd23..073c81b6f8 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 @@ -23,6 +23,7 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_ 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.IpVersion import net.mullvad.mullvadvpn.lib.model.Mtu import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port @@ -72,6 +73,7 @@ class VpnSettingsScreenTest { navigateToShadowSocksSettings: () -> Unit = {}, navigateToUdp2TcpSettings: () -> Unit = {}, onToggleAutoStartAndConnectOnBoot: (Boolean) -> Unit = {}, + onSelectDeviceIpVersion: (Constraint<IpVersion>) -> Unit = {}, ) { setContentWithTheme { VpnSettingsScreen( @@ -103,6 +105,7 @@ class VpnSettingsScreenTest { navigateToShadowSocksSettings = navigateToShadowSocksSettings, navigateToUdp2TcpSettings = navigateToUdp2TcpSettings, onToggleAutoStartAndConnectOnBoot = onToggleAutoStartAndConnectOnBoot, + onSelectDeviceIpVersion = onSelectDeviceIpVersion, ) } } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationUseCaseTest.kt index deef7b7ab9..9974da6a17 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationUseCaseTest.kt @@ -48,6 +48,7 @@ class SelectedLocationUseCaseTest { isMultihopEnabled = true, entryLocation = entryLocation, port = Constraint.Any, + ipVersion = Constraint.Any, ) selectedLocation.value = exitLocation diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/MultihopViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/MultihopViewModelTest.kt index 34cb1353bb..c51d7e9f48 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/MultihopViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/MultihopViewModelTest.kt @@ -48,6 +48,7 @@ class MultihopViewModelTest { isMultihopEnabled = true, entryLocation = Constraint.Any, port = Constraint.Any, + ipVersion = Constraint.Any, ) // Act, Assert diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt index 7bc05df05c..b71d217408 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt @@ -108,6 +108,7 @@ class SettingsViewModelTest { isMultihopEnabled = true, entryLocation = Constraint.Any, port = Constraint.Any, + ipVersion = Constraint.Any, ) // Act, Assert diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt index aae283e91e..9d7ed39622 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.viewmodel import androidx.lifecycle.viewModelScope import app.cash.turbine.test import arrow.core.right +import io.mockk.Awaits import io.mockk.Runs import io.mockk.coEvery import io.mockk.coVerify @@ -18,10 +19,10 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest -import mullvad_daemon.management_interface.daitaSettings import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.DaitaSettings +import net.mullvad.mullvadvpn.lib.model.IpVersion import net.mullvad.mullvadvpn.lib.model.Mtu import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.PortRange @@ -163,6 +164,7 @@ class VpnSettingsViewModelTest { every { mockRelaySettings.relayConstraints } returns mockRelayConstraints every { mockRelayConstraints.wireguardConstraints } returns mockWireguardConstraints every { mockWireguardConstraints.port } returns expectedPort + every { mockWireguardConstraints.ipVersion } returns Constraint.Any every { mockSettings.tunnelOptions } returns TunnelOptions( wireguard = @@ -193,6 +195,7 @@ class VpnSettingsViewModelTest { port = wireguardPort, isMultihopEnabled = false, entryLocation = Constraint.Any, + ipVersion = Constraint.Any, ) coEvery { mockWireguardConstraintsRepository.setWireguardPort(any()) } returns Unit.right() @@ -249,4 +252,42 @@ class VpnSettingsViewModelTest { mockAutoStartAndConnectOnBootRepository.setAutoStartAndConnectOnBoot(targetState) } } + + @Test + fun `when device ip version is IPv6 then UiState should be IPv6`() = runTest { + // Arrange + val ipVersion = Constraint.Only(IpVersion.IPV6) + val mockSettings = mockk<Settings>(relaxed = true) + every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.ipVersion } returns + ipVersion + every { mockSettings.tunnelOptions.wireguard } returns + WireguardTunnelOptions( + mtu = Mtu(0), + quantumResistant = QuantumResistantState.Off, + daitaSettings = DaitaSettings(enabled = false, directOnly = false), + ) + every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.port } returns + Constraint.Any + + // Act, Assert + viewModel.uiState.test { + // Default value + awaitItem() + mockSettingsUpdate.value = mockSettings + assertEquals(ipVersion, awaitItem().deviceIpVersion) + } + } + + @Test + fun `calling onDeviceIpVersionSelected should call setDeviceIpVersion`() = runTest { + // Arrange + val targetState = Constraint.Only(IpVersion.IPV4) + coEvery { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) } just Awaits + + // Act + viewModel.onDeviceIpVersionSelected(targetState) + + // Assert + coVerify(exactly = 1) { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) } + } } |
