Skip to content

Commit

Permalink
Add unit tests for out of time behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Sep 7, 2023
1 parent 67d7cd4 commit cc729a2
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import io.mockk.unmockkAll
import io.mockk.verify
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlinx.coroutines.async
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import net.mullvad.mullvadvpn.compose.state.ConnectNotificationState
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
Expand All @@ -36,6 +38,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.authTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.util.appVersionCallbackFlow
import net.mullvad.talpid.tunnel.ErrorState
import net.mullvad.talpid.tunnel.ErrorStateCause
import net.mullvad.talpid.util.EventNotifier
import org.joda.time.DateTime
import org.joda.time.ReadableInstant
Expand Down Expand Up @@ -404,6 +407,29 @@ class ConnectViewModelTest {
}
}

@Test
fun testOutOfTimeViewAction() =
runTest(testCoroutineRule.testDispatcher) {
// Arrange
val errorStateCause = ErrorStateCause.AuthFailed("[EXPIRED_ACCOUNT]")
val tunnelRealStateTestItem = TunnelState.Error(ErrorState(errorStateCause, true))
val deferred = async { viewModel.viewActions.first() }

// Act
viewModel.uiState.test {
awaitItem()
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
locationSlot.captured.invoke(mockLocation)
relaySlot.captured.invoke(mockk(), mockk())
eventNotifierTunnelRealState.notify(tunnelRealStateTestItem)
awaitItem()
}

// Assert
assertIs<ConnectViewModel.ViewAction.OpenOutOfTimeView>(deferred.await())
}

companion object {
private const val CACHE_EXTENSION_CLASS = "net.mullvad.mullvadvpn.util.CacheExtensionsKt"
private const val SERVICE_CONNECTION_MANAGER_EXTENSIONS =
Expand Down

0 comments on commit cc729a2

Please sign in to comment.