Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jul 25, 2024
1 parent fea0ea1 commit 2efa4c2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_COUNTRIES
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.SAVE_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.RelayItem
Expand Down Expand Up @@ -80,19 +81,22 @@ class CustomListLocationsScreenTest {
CustomListLocationsScreen(
state =
CustomListLocationsUiState.Content.Data(
locations = emptyList(),
locations =
listOf(
RelayLocationListItem(DUMMY_RELAY_COUNTRIES[0], checked = true),
RelayLocationListItem(
DUMMY_RELAY_COUNTRIES[1],
checked = false
),
),
searchTerm = ""
),
)
}

// Assert
onNodeWithText("Relay Country 1").assertExists()
onNodeWithText("Relay City 1").assertDoesNotExist()
onNodeWithText("Relay host 1").assertDoesNotExist()
onNodeWithText("Relay Country 2").assertExists()
onNodeWithText("Relay City 2").assertDoesNotExist()
onNodeWithText("Relay host 2").assertDoesNotExist()
}

@Test
Expand All @@ -106,7 +110,8 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
locations = emptyList()
locations =
listOf(RelayLocationListItem(selectedCountry, checked = true))
),
onRelaySelectionClick = mockedOnRelaySelectionClicked
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ sealed interface CustomListLocationsUiState {

data class Data(
override val newList: Boolean = false,
val locations: List<RelayLocationItem>,
val locations: List<RelayLocationListItem>,
override val searchTerm: String = "",
override val saveEnabled: Boolean = false,
override val hasUnsavedChanges: Boolean = false
) : Content
}
}

data class RelayLocationItem(
data class RelayLocationListItem(
val item: RelayItem.Location,
val depth: Int,
val checked: Boolean,
val expanded: Boolean
val depth: Int = 0,
val checked: Boolean = false,
val expanded: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.compose.communication.CustomListAction
import net.mullvad.mullvadvpn.compose.communication.LocationsChanged
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
import net.mullvad.mullvadvpn.compose.state.RelayLocationItem
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
import net.mullvad.mullvadvpn.lib.model.RelayItem
import net.mullvad.mullvadvpn.lib.model.RelayItemId
import net.mullvad.mullvadvpn.relaylist.MIN_SEARCH_LENGTH
Expand Down Expand Up @@ -239,11 +239,11 @@ class CustomListLocationsViewModel(
isSelected: (RelayItem) -> Boolean,
isExpanded: (RelayItemId) -> Boolean,
depth: Int = 0,
): List<RelayLocationItem> = flatMap { relayItem ->
buildList<RelayLocationItem> {
): List<RelayLocationListItem> = flatMap { relayItem ->
buildList<RelayLocationListItem> {
val expanded = isExpanded(relayItem.id)
add(
RelayLocationItem(
RelayLocationListItem(
item = relayItem,
depth = depth,
checked = isSelected(relayItem),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListAction
import net.mullvad.mullvadvpn.compose.communication.LocationsChanged
import net.mullvad.mullvadvpn.compose.screen.CustomListLocationsNavArgs
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
import net.mullvad.mullvadvpn.compose.state.RelayLocationItem
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.lib.common.test.assertLists
import net.mullvad.mullvadvpn.lib.model.CustomList
Expand Down Expand Up @@ -71,7 +71,7 @@ class CustomListLocationsViewModelTest {
// Arrange
val expectedList =
DUMMY_COUNTRIES.map {
RelayLocationItem(
RelayLocationListItem(
item = it,
depth = it.toDepth(),
checked = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ class SelectLocationViewModelTest {
assertIs<SelectLocationUiState.Content>(actualState)
assertLists(
testCountries.map { it.id },
actualState.relayListItems.mapNotNull { it.relayItemId() })
actualState.relayListItems.mapNotNull { it.relayItemId() }
)
assertTrue(
actualState.relayListItems
.filterIsInstance<RelayListItem.SelectableItem>()
.first { it.relayItemId() == selectedId }
.isSelected)
.isSelected
)
}
}

Expand All @@ -140,11 +142,13 @@ class SelectLocationViewModelTest {
assertIs<SelectLocationUiState.Content>(actualState)
assertLists(
testCountries.map { it.id },
actualState.relayListItems.mapNotNull { it.relayItemId() })
actualState.relayListItems.mapNotNull { it.relayItemId() }
)
assertTrue(
actualState.relayListItems.filterIsInstance<RelayListItem.SelectableItem>().all {
!it.isSelected
})
}
)
}
}

Expand Down Expand Up @@ -191,7 +195,8 @@ class SelectLocationViewModelTest {
assertTrue(
actualState.relayListItems.filterIsInstance<RelayListItem.GeoLocationItem>().any {
it.item is RelayItem.Location.City && it.item.name == "Gothenburg"
})
}
)
}
}

Expand All @@ -218,7 +223,8 @@ class SelectLocationViewModelTest {
assertIs<SelectLocationUiState.Content>(actualState)
assertEquals(
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
actualState.relayListItems)
actualState.relayListItems
)
}
}

Expand Down Expand Up @@ -278,7 +284,8 @@ class SelectLocationViewModelTest {
CustomList(
id = CustomListId("1"),
name = CustomListName.fromString("custom"),
locations = emptyList()),
locations = emptyList()
),
locations = emptyList(),
)
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
Expand Down Expand Up @@ -321,7 +328,11 @@ class SelectLocationViewModelTest {
RelayItem.Location.City(
id = GeoLocationId.City(GeoLocationId.Country("se"), "got"),
"Gothenburg",
emptyList()))),
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList()))
emptyList()
)
)
),
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList())
)
}
}

0 comments on commit 2efa4c2

Please sign in to comment.