Skip to content

Commit c17b6fa

Browse files
committed
Fix and add tests
1 parent c2f164d commit c17b6fa

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-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

+42-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
@@ -163,6 +164,7 @@ class VpnSettingsViewModelTest {
163164
every { mockRelaySettings.relayConstraints } returns mockRelayConstraints
164165
every { mockRelayConstraints.wireguardConstraints } returns mockWireguardConstraints
165166
every { mockWireguardConstraints.port } returns expectedPort
167+
every { mockWireguardConstraints.ipVersion } returns Constraint.Any
166168
every { mockSettings.tunnelOptions } returns
167169
TunnelOptions(
168170
wireguard =
@@ -193,6 +195,7 @@ class VpnSettingsViewModelTest {
193195
port = wireguardPort,
194196
isMultihopEnabled = false,
195197
entryLocation = Constraint.Any,
198+
ipVersion = Constraint.Any,
196199
)
197200
coEvery { mockWireguardConstraintsRepository.setWireguardPort(any()) } returns
198201
Unit.right()
@@ -249,4 +252,42 @@ class VpnSettingsViewModelTest {
249252
mockAutoStartAndConnectOnBootRepository.setAutoStartAndConnectOnBoot(targetState)
250253
}
251254
}
255+
256+
@Test
257+
fun `when device ip version is IPv6 then UiState should be IPv6`() = runTest {
258+
// Arrange
259+
val ipVersion = Constraint.Only(IpVersion.IPV6)
260+
val mockSettings = mockk<Settings>(relaxed = true)
261+
every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.ipVersion } returns
262+
ipVersion
263+
every { mockSettings.tunnelOptions.wireguard } returns
264+
WireguardTunnelOptions(
265+
mtu = Mtu(0),
266+
quantumResistant = QuantumResistantState.Off,
267+
daitaSettings = DaitaSettings(enabled = false, directOnly = false),
268+
)
269+
every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.port } returns
270+
Constraint.Any
271+
272+
// Act, Assert
273+
viewModel.uiState.test {
274+
// Default value
275+
awaitItem()
276+
mockSettingsUpdate.value = mockSettings
277+
assertEquals(ipVersion, awaitItem().deviceIpVersion)
278+
}
279+
}
280+
281+
@Test
282+
fun `calling onDeviceIpVersionSelected should call setDeviceIpVersion`() = runTest {
283+
// Arrange
284+
val targetState = Constraint.Only(IpVersion.IPV4)
285+
coEvery { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) } just Awaits
286+
287+
// Act
288+
viewModel.onDeviceIpVersionSelected(targetState)
289+
290+
// Assert
291+
coVerify(exactly = 1) { mockWireguardConstraintsRepository.setDeviceIpVersion(targetState) }
292+
}
252293
}

0 commit comments

Comments
 (0)