Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Dec 23, 2024
1 parent 7a296f0 commit 6d7a872
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConnectViewModel(
tunnelState = tunnelState,
showLocation =
when (tunnelState) {
is TunnelState.Disconnected -> true
is TunnelState.Disconnected -> tunnelState.location != null
is TunnelState.Disconnecting -> {
when (tunnelState.actionAfterDisconnect) {
ActionAfterDisconnect.Nothing -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ class ConnectViewModelTest {
fun `given RelayListUseCase returns new selectedRelayItem uiState should emit new selectedRelayItem`() =
runTest {
val selectedRelayItemTitle = "Item"
selectedRelayItemFlow.value = selectedRelayItemTitle

viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
val result = awaitItem()
assertEquals(selectedRelayItemTitle, result.selectedRelayItemTitle)

selectedRelayItemFlow.value = selectedRelayItemTitle
assertEquals(selectedRelayItemTitle, awaitItem().selectedRelayItemTitle)
}
}

Expand All @@ -196,7 +195,6 @@ class ConnectViewModelTest {

// Act, Assert
viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
tunnelState.emit(TunnelState.Disconnected(null))

// Start of with no location
Expand All @@ -215,12 +213,7 @@ class ConnectViewModelTest {
val locationTestItem = null

// Act, Assert
viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
expectNoEvents()
val result = awaitItem()
assertEquals(locationTestItem, result.location)
}
viewModel.uiState.test { assertEquals(locationTestItem, awaitItem().location) }
}

@Test
Expand Down Expand Up @@ -278,15 +271,12 @@ class ConnectViewModelTest {
val mockErrorState: ErrorState = mockk()
val expectedConnectNotificationState =
InAppNotification.TunnelStateError(mockErrorState)
val tunnelStateError = TunnelState.Error(mockErrorState)
notifications.value = listOf(expectedConnectNotificationState)

// Act, Assert
viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
tunnelState.emit(tunnelStateError)
val result = awaitItem()
assertEquals(expectedConnectNotificationState, result.inAppNotification)
notifications.value = listOf(expectedConnectNotificationState)
assertEquals(expectedConnectNotificationState, awaitItem().inAppNotification)
}
}

Expand Down Expand Up @@ -315,7 +305,6 @@ class ConnectViewModelTest {
viewModel.uiState.test {
awaitItem()
outOfTimeViewFlow.value = true
awaitItem()
}

// Assert
Expand All @@ -328,12 +317,13 @@ class ConnectViewModelTest {
// Arrange
val tunnel = TunnelState.Error(mockk(relaxed = true))
val lastKnownLocation: GeoIpLocation = mockk(relaxed = true)
lastKnownLocationFlow.emit(lastKnownLocation)
tunnelState.emit(tunnel)

// Act, Assert
viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
lastKnownLocationFlow.emit(lastKnownLocation)
tunnelState.emit(tunnel)
awaitItem()
val result = awaitItem()
assertEquals(lastKnownLocation, result.location)
}
Expand Down

0 comments on commit 6d7a872

Please sign in to comment.