Skip to content

Commit

Permalink
Add unit test for system vpn settings available
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Feb 8, 2024
1 parent 3782f76 commit 9f5768e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Settings?>(null)
private val portRangeFlow = MutableStateFlow(emptyList<PortRange>())
Expand All @@ -56,6 +58,7 @@ class VpnSettingsViewModelTest {
resources = mockResources,
portRangeUseCase = mockPortRangeUseCase,
relayListUseCase = mockRelayListUseCase,
systemVpnSettingsUseCase = mockSystemVpnSettingsUseCase,
dispatcher = UnconfinedTestDispatcher()
)
}
Expand Down Expand Up @@ -146,4 +149,17 @@ class VpnSettingsViewModelTest {
mockRelayListUseCase.updateSelectedWireguardConstraints(wireguardConstraints)
}
}

@Test
fun `given VpnSettingsViewModel when use case systemVpnSettingsAvailable is true then ui state isSystemVpnSettingsAvailable should be true`() =
runTest {
val systemVpnSettingsAvailable = true

every { mockSystemVpnSettingsUseCase.systemVpnSettingsAvailable() } returns
systemVpnSettingsAvailable

viewModel.uiState.test {
assertEquals(systemVpnSettingsAvailable, awaitItem().systemVpnSettingsAvailable)
}
}
}

0 comments on commit 9f5768e

Please sign in to comment.