From 0477e6a75b2487daca6919d400c898b7b12540cc Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Thu, 8 Feb 2024 16:51:18 +0100 Subject: [PATCH] Add unit test for system vpn settings available --- .../viewmodel/VpnSettingsViewModelTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 51bbe3057c4c..5d44dca487f0 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 @@ -27,6 +27,7 @@ import net.mullvad.mullvadvpn.model.WireguardTunnelOptions import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.usecase.PortRangeUseCase import net.mullvad.mullvadvpn.usecase.RelayListUseCase +import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -39,6 +40,7 @@ class VpnSettingsViewModelTest { private val mockResources: Resources = mockk() private val mockPortRangeUseCase: PortRangeUseCase = mockk() private val mockRelayListUseCase: RelayListUseCase = mockk() + private val mockSystemVpnSettingsUseCase: SystemVpnSettingsUseCase = mockk(relaxed = true) private val mockSettingsUpdate = MutableStateFlow(null) private val portRangeFlow = MutableStateFlow(emptyList()) @@ -56,6 +58,7 @@ class VpnSettingsViewModelTest { resources = mockResources, portRangeUseCase = mockPortRangeUseCase, relayListUseCase = mockRelayListUseCase, + systemVpnSettingsUseCase = mockSystemVpnSettingsUseCase, dispatcher = UnconfinedTestDispatcher() ) } @@ -146,4 +149,17 @@ class VpnSettingsViewModelTest { mockRelayListUseCase.updateSelectedWireguardConstraints(wireguardConstraints) } } + + @Test + fun `given useCase systemVpnSettingsAvailable is true then uiState should be systemVpnSettingsAvailable=true`() = + runTest { + val systemVpnSettingsAvailable = true + + every { mockSystemVpnSettingsUseCase.systemVpnSettingsAvailable() } returns + systemVpnSettingsAvailable + + viewModel.uiState.test { + assertEquals(systemVpnSettingsAvailable, awaitItem().systemVpnSettingsAvailable) + } + } }