Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jan 7, 2025
1 parent fd77dbe commit c0238db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ConnectScreenTest {
)

// Assert
onNodeWithText("DISCONNECTED").assertExists()
onNodeWithText("DISCONNECTING...").assertExists()
onNodeWithText(mockLocationName).assertExists()
onNodeWithText("Disconnect").assertExists()
}
Expand Down Expand Up @@ -226,7 +226,7 @@ class ConnectScreenTest {
// Assert
onNodeWithText("BLOCKED CONNECTION").assertExists()
onNodeWithText(mockLocationName).assertExists()
onNodeWithText("Disconnect").assertExists()
onNodeWithText("Unblock").assertExists()
onNodeWithText("BLOCKING INTERNET").assertExists()
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ class ConnectScreenTest {
)

// Assert
onNodeWithText("CONNECTED").assertExists()
onNodeWithText("BLOCKING...").assertExists()
onNodeWithText(mockLocationName).assertExists()
onNodeWithText("Disconnect").assertExists()
onNodeWithText("BLOCKING INTERNET").assertExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 c0238db

Please sign in to comment.