From 2efa4c2a6a9bc88d675d17e62cf2b5a72b48d3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Thu, 25 Jul 2024 10:35:59 +0200 Subject: [PATCH] Fix more tests --- .../screen/CustomListLocationsScreenTest.kt | 17 +++++++---- .../state/CustomListLocationsUiState.kt | 10 +++---- .../viewmodel/CustomListLocationsViewModel.kt | 8 ++--- .../CustomListLocationsViewModelTest.kt | 4 +-- .../viewmodel/SelectLocationViewModelTest.kt | 29 +++++++++++++------ 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt index e7e490c09a08..1a8d35a5a907 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt @@ -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 @@ -80,7 +81,14 @@ 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 = "" ), ) @@ -88,11 +96,7 @@ class CustomListLocationsScreenTest { // 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 @@ -106,7 +110,8 @@ class CustomListLocationsScreenTest { state = CustomListLocationsUiState.Content.Data( newList = false, - locations = emptyList() + locations = + listOf(RelayLocationListItem(selectedCountry, checked = true)) ), onRelaySelectionClick = mockedOnRelaySelectionClicked ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/CustomListLocationsUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/CustomListLocationsUiState.kt index 3bff852c3810..c9c842ee0b46 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/CustomListLocationsUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/CustomListLocationsUiState.kt @@ -22,7 +22,7 @@ sealed interface CustomListLocationsUiState { data class Data( override val newList: Boolean = false, - val locations: List, + val locations: List, override val searchTerm: String = "", override val saveEnabled: Boolean = false, override val hasUnsavedChanges: Boolean = false @@ -30,9 +30,9 @@ sealed interface CustomListLocationsUiState { } } -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 ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt index c99024b56b27..3df2b2f623cf 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt @@ -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 @@ -239,11 +239,11 @@ class CustomListLocationsViewModel( isSelected: (RelayItem) -> Boolean, isExpanded: (RelayItemId) -> Boolean, depth: Int = 0, - ): List = flatMap { relayItem -> - buildList { + ): List = flatMap { relayItem -> + buildList { val expanded = isExpanded(relayItem.id) add( - RelayLocationItem( + RelayLocationListItem( item = relayItem, depth = depth, checked = isSelected(relayItem), diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt index f80d9be53fcd..d2eaedd8c279 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt @@ -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 @@ -71,7 +71,7 @@ class CustomListLocationsViewModelTest { // Arrange val expectedList = DUMMY_COUNTRIES.map { - RelayLocationItem( + RelayLocationListItem( item = it, depth = it.toDepth(), checked = false, diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt index 621912f6d397..d15e460e5d78 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt @@ -119,12 +119,14 @@ class SelectLocationViewModelTest { assertIs(actualState) assertLists( testCountries.map { it.id }, - actualState.relayListItems.mapNotNull { it.relayItemId() }) + actualState.relayListItems.mapNotNull { it.relayItemId() } + ) assertTrue( actualState.relayListItems .filterIsInstance() .first { it.relayItemId() == selectedId } - .isSelected) + .isSelected + ) } } @@ -140,11 +142,13 @@ class SelectLocationViewModelTest { assertIs(actualState) assertLists( testCountries.map { it.id }, - actualState.relayListItems.mapNotNull { it.relayItemId() }) + actualState.relayListItems.mapNotNull { it.relayItemId() } + ) assertTrue( actualState.relayListItems.filterIsInstance().all { !it.isSelected - }) + } + ) } } @@ -191,7 +195,8 @@ class SelectLocationViewModelTest { assertTrue( actualState.relayListItems.filterIsInstance().any { it.item is RelayItem.Location.City && it.item.name == "Gothenburg" - }) + } + ) } } @@ -218,7 +223,8 @@ class SelectLocationViewModelTest { assertIs(actualState) assertEquals( listOf(RelayListItem.LocationsEmptyText(mockSearchString)), - actualState.relayListItems) + actualState.relayListItems + ) } } @@ -278,7 +284,8 @@ class SelectLocationViewModelTest { CustomList( id = CustomListId("1"), name = CustomListName.fromString("custom"), - locations = emptyList()), + locations = emptyList() + ), locations = emptyList(), ) coEvery { mockCustomListActionUseCase(any()) } returns @@ -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()) + ) } }