Skip to content

Commit 0829a9e

Browse files
committed
Fix and add tests
1 parent d93de34 commit 0829a9e

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_
2323
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG
2424
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG
2525
import net.mullvad.mullvadvpn.lib.model.Constraint
26+
import net.mullvad.mullvadvpn.lib.model.IpVersion
2627
import net.mullvad.mullvadvpn.lib.model.Mtu
2728
import net.mullvad.mullvadvpn.lib.model.ObfuscationMode
2829
import net.mullvad.mullvadvpn.lib.model.Port
@@ -72,6 +73,7 @@ class VpnSettingsScreenTest {
7273
navigateToShadowSocksSettings: () -> Unit = {},
7374
navigateToUdp2TcpSettings: () -> Unit = {},
7475
onToggleAutoStartAndConnectOnBoot: (Boolean) -> Unit = {},
76+
onSelectDeviceIpVersion: (Constraint<IpVersion>) -> Unit = {},
7577
) {
7678
setContentWithTheme {
7779
VpnSettingsScreen(
@@ -103,6 +105,7 @@ class VpnSettingsScreenTest {
103105
navigateToShadowSocksSettings = navigateToShadowSocksSettings,
104106
navigateToUdp2TcpSettings = navigateToUdp2TcpSettings,
105107
onToggleAutoStartAndConnectOnBoot = onToggleAutoStartAndConnectOnBoot,
108+
onSelectDeviceIpVersion = onSelectDeviceIpVersion,
106109
)
107110
}
108111
}

android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationUseCaseTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SelectedLocationUseCaseTest {
4848
isMultihopEnabled = true,
4949
entryLocation = entryLocation,
5050
port = Constraint.Any,
51+
ipVersion = Constraint.Any,
5152
)
5253
selectedLocation.value = exitLocation
5354

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/MultihopViewModelTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class MultihopViewModelTest {
4848
isMultihopEnabled = true,
4949
entryLocation = Constraint.Any,
5050
port = Constraint.Any,
51+
ipVersion = Constraint.Any,
5152
)
5253

5354
// Act, Assert

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class SettingsViewModelTest {
108108
isMultihopEnabled = true,
109109
entryLocation = Constraint.Any,
110110
port = Constraint.Any,
111+
ipVersion = Constraint.Any,
111112
)
112113

113114
// Act, Assert

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.viewmodel
33
import androidx.lifecycle.viewModelScope
44
import app.cash.turbine.test
55
import arrow.core.right
6+
import io.mockk.Awaits
67
import io.mockk.Runs
78
import io.mockk.coEvery
89
import io.mockk.coVerify
@@ -18,10 +19,10 @@ import kotlinx.coroutines.cancel
1819
import kotlinx.coroutines.flow.MutableStateFlow
1920
import kotlinx.coroutines.test.UnconfinedTestDispatcher
2021
import kotlinx.coroutines.test.runTest
21-
import mullvad_daemon.management_interface.daitaSettings
2222
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
2323
import net.mullvad.mullvadvpn.lib.model.Constraint
2424
import net.mullvad.mullvadvpn.lib.model.DaitaSettings
25+
import net.mullvad.mullvadvpn.lib.model.IpVersion
2526
import net.mullvad.mullvadvpn.lib.model.Mtu
2627
import net.mullvad.mullvadvpn.lib.model.Port
2728
import net.mullvad.mullvadvpn.lib.model.PortRange
@@ -193,6 +194,7 @@ class VpnSettingsViewModelTest {
193194
port = wireguardPort,
194195
isMultihopEnabled = false,
195196
entryLocation = Constraint.Any,
197+
ipVersion = Constraint.Any,
196198
)
197199
coEvery { mockWireguardConstraintsRepository.setWireguardPort(any()) } returns
198200
Unit.right()
@@ -249,4 +251,42 @@ class VpnSettingsViewModelTest {
249251
mockAutoStartAndConnectOnBootRepository.setAutoStartAndConnectOnBoot(targetState)
250252
}
251253
}
254+
255+
@Test
256+
fun `when device ip version is IPv6 then UiState should be IPv6`() = runTest {
257+
// Arrange
258+
val ipVersion = Constraint.Only(IpVersion.IPV6)
259+
val mockSettings = mockk<Settings>(relaxed = true)
260+
every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.ipVersion } returns
261+
ipVersion
262+
every { mockSettings.tunnelOptions.wireguard } returns
263+
WireguardTunnelOptions(
264+
mtu = Mtu(0),
265+
quantumResistant = QuantumResistantState.Off,
266+
daitaSettings = DaitaSettings(enabled = false, directOnly = false),
267+
)
268+
every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.port } returns
269+
Constraint.Any
270+
271+
// Act, Assert
272+
viewModel.uiState.test {
273+
// Default value
274+
awaitItem()
275+
mockSettingsUpdate.value = mockSettings
276+
assertEquals(ipVersion, awaitItem().deviceIpVersion)
277+
}
278+
}
279+
280+
@Test
281+
fun `calling onDeviceIpVersionSelected should call setDeviceIpVersion`() = runTest {
282+
// Arrange
283+
val targetState = Constraint.Only(IpVersion.IPV4)
284+
coEvery { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) } just Awaits
285+
286+
// Act
287+
viewModel.onDeviceIpVersionSelected(targetState)
288+
289+
// Assert
290+
coVerify(exactly = 1) { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) }
291+
}
252292
}

0 commit comments

Comments
 (0)